Go left! no! go right!
While learning to move the player around, I relyed heavily on the godot docs. Mainly, two articles:
Running
To have the player run, I set it’s velocity toward the bottom of the hill and call “move_and_slide”.
I initally had a mixup in the axis, moving the player along the X axis, thus needing to rotate the player in 90 degrees – for no reason save for the fact that I did it and ran with it (pun intended).
Note to self: If the player is running down, the axis to run on is the Y axis.
I then separated the speed used for the velocity to a variable and named it “CURRENT_SPEED”.
This will allow me to mess with the current speed down the line.
Turning
To turn, I’ll need to set the proxy’s rotation with and updated value before calling “move_and_slide”.
The new value is based on 4 different variables:
- delta (time since last frame rendered) – A value received as part of Godot’s physics engine.
- rotation – The current rotation of the proxy.
- ROTATION_DIRECTION (variable) – Can be on of: -1, 0, 1. defining wither a turn towards a direction or no turn at all.
This value was initially tested using player input, but the not to long future, It can be set by either the player, or an enemy manager and more. - ROTATION_SPEED (variable) – A developer defined variable to control the turn speed.
First, I’ll need to calculate the “rotation_diff”, the amount to add to the current rotation.
Once I have the rotation difference, I can add it to the current rotation and set it to the proxy’s rotation.
Ok, looking good!
Finally, I can clamp the result to make sure The player can’t turn over set values: