fancy movement
Initially, the player movement was: if the button to move left is being pressed, the player is moved left by a number of pixels. This is snappy and feels easy to control but I want this project to be like a physics simulation with friction and forces, so I have changed the player movement and the stick throwing. Pressing the button to move left now initiates a force to the left that acts against friction to give a total force and then an acceleration, used to update the player’s velocity. This also gives a natural max speed of the player and plenty of variables I can tweak to make movement feel different in different areas or when carrying heavy objects. The player has a mass and an output force and the surface has a friction value. The values I have picked are just numbers that looked and felt OK and there are plenty of tweaks to make to make this more physically accurate but it is a start. Here is a snippet of the code to move the player:
I also added sprinting which neatly lent itself to increasing the player’s force in this more physics-based movement:
Here is a gif of the player moving with SURFACE_FRICTION set to 0.1:
I also added a shadow to the stick that shows its actual 2D location when it is being thrown, not shown in the clip.