Asylum Dev Diary 103 – Footsteps

Development has been continuing during the lockdown from the coronavirus outbreak.

Over the last week or so I’ve been updating a few of the sprites that didn’t look quite right. One of these is the janitor’s cart. Previously I had used a photo of the side of a cart taken from an image library. It looked OK but it restricted what I could do with it. So, that, along with a few other sprites, has been replaced by a 3d model render. This allows me to remove elements and create more unique environments. The janitor’s cart, for example, comes with different containers, spray bottles and a slippery floor sign.

The next major change was how I was animating the player. One thing I want to do is to change the players outfit depending on different circumstances. While he’s in the asylum he is wearing a torn up straitjacket and has bare feet, however this shouldn’t be the case during the flashback sequences. The current method I was using for the player was to create a sprite stripe (an image that contains all the frames for an animation) in 2 pieces; firstly there is the players body and head, the body swings the shoulders back and forth slightly and the head reacts tiny amounts, secondly, the feet sprite which are animated in step formation. The player is drawn from these two sprites.

While this works it is restrictive so i wanted to change it so that the pieces are all separate and that means I would have to code the animation but it would allow me to very easily change to the elements of the player (shoes, jacket, even the head if necessary).

Figure 1: Code from the Draw event that works out where to draw the feet and shoulders.

var feetApartDist=18;
var f1x=x-lengthdir_x(feetApartDist,motionAngle-90);
var f1y=y-lengthdir_y(feetApartDist,motionAngle-90);

var f2x=x-lengthdir_x(feetApartDist,motionAngle+90);
var f2y=y-lengthdir_y(feetApartDist,motionAngle+90);

f1x=f1x+lengthdir_x(movementBobFeet,motionAngle);f1y=f1y+lengthdir_y(movementBobFeet,motionAngle);
f2x=f2x+lengthdir_x(-movementBobFeet,motionAngle);f2y=f2y+lengthdir_y(-movementBobFeet,motionAngle);

Figure 2: Code from the Step event that updates the motion and position for the feet and shoulders.

//code prior to this handles keyboard and mouse input variables and collisions.

if (hsp!=0 || vsp!=0){
	if (runModify==1){
		image_speed=2.5;
	}else{
		image_speed=1.5;	
	}
	movementBob=lerp(movementBob,movementBob+(movementBobDir*10),image_speed/25);
	movementBobFeet=lerp(movementBobFeet,movementBobFeet+(movementBobFeetDir*6),image_speed/9);
	if(movementBob>10 || movementBob<-10){movementBobDir=-movementBobDir;}
	if(movementBobFeet>8 || movementBobFeet<-8){movementBobFeetDir=-movementBobFeetDir;}
}else{
	image_speed=0;
	image_index = 0;
	movementBob=0;
	movementBobFeet=0;
}

There are a few other player specific variables used here that are set up in the players Create event so the code posted is just an example. Basically, I calculate the angle that the feet are supposed to be in (the motionAngle of the player) and then draw each foot a set distance away from the player centre, they are then offset along the y axis depending on a position variable that I ping-pong back and forth to create the motion. This same practise is used for the shoulders.

With the head and shoulders now separate I could even look to controlling the head in new ways, perhaps to glance at important items as the player moves around.