Attach a new Script to the Hero node.
Ensure the Template is EMPTY
We have COMPLETE control over the attributes
we can assign to our character.
However the most common properties are for speed,
gravity, jump height etc.
These are constants which means that their value cannot change while the game is running.
However, you can make them standard variables and change the values as you collect powerups etc.
Set your own gravity var or get it from project settings ensuring all physics bodies use the same gravity.
You can find this value in the project settings menu:
In the physics process find out which direction the character is moving in:
If we are not on the floor,
gravity should pull us down.
Note that Y-Axis is NEGATIVE in the Up direction.
The standard frames per second for Godot can be adjusted here:
If on the floor and we press jump key
We jump at full strength.
If already in air and release jump key
If we are moving, accelerate up to our max speed
Moving FROM current speed, TO max speed at acceleration rate over time
Note that this time we move towards an X velocity of 0 from our current velocity.
move_and_slide() is a built-in function which simplifies character movement.
Moves the body based on velocity. If the body collides with another, it will slide along the other body (by default only on floor) rather than stop immediately. If the other body is a CharacterBody2D or RigidBody2D, it will also be affected by the motion of the other body. You can use this to make moving and rotating platforms, or to make nodes push other nodes.