CHARACTER SCRIPT

Attach a new Script to the Hero node.

Ensure the Template is EMPTY

CHARACTER PROPERTIES

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.

Set these up now:

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:

GET DIRECTION

In the physics process find out which direction the character is moving in:

APPLY GRAVITY

If we are not on the floor, 

gravity should pull us down.

Note that Y-Axis is NEGATIVE in the Up direction.

FRAMES PER SECOND

The standard frames per second for Godot can be adjusted here:

HANDLE JUMPING

If on the floor and we press jump key

We jump at full strength.

Otherwise

If already in air and release jump key

Halve our Jump strength.

HANDLE ACCELERATION

If we are moving, accelerate up to our max speed

Moving FROM current speed, TO max speed at acceleration rate over time

Note how the move_toward

 built-in function works.

HANDLE DECELERATION

Note that this time we move towards an X velocity of 0 from our current velocity.

CALL ALL THE FUNCTIONS!

MOVE AND SLIDE

move_and_slide() is a built-in function which simplifies character movement.

What does it do:

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.