Code skill The Player’s Position

This piece of code will work out the position of the player in the world and how far away they are from the nearest platform. By creating a GetDistanceToFloor function, you can work out which platform is below the right-hand corner of the player and how high that platform is. The applyGravity function will work out how far the player needs to fall to land on the platform.

See the Pen GB5 M4 by Walker Books UK (@walkerbooks) on CodePen.