Move Speed
Move Speed
Multiply the dir vector x and z by the move_speed variable
Multiply the dir vector x and z by the move_speed variable
To increase player speed
To increase player speed
Model Rotation
Model Rotation
The model always stares at the camera.
The model always stares at the camera.
Code it to rotate in the movement direction.
Code it to rotate in the movement direction.
Note that x and y are reversed.
Note that x and y are reversed.
This is because we want the y value rotation
This is because we want the y value rotation
Therefore y value comes first.
Therefore y value comes first.
Y value is the horizontal rotation
Y value is the horizontal rotation
Look at the Green line around the player
Look at the Green line around the player
To prevent the model snapping back
To prevent the model snapping back
Code it to only rotate if we are moving.
Code it to only rotate if we are moving.
Player now remains facing current position
Player now remains facing current position
To make the animations look
To make the animations look
smoother we will lerp the angle.
smoother we will lerp the angle.
Lerp stands for Linear Interpolation
Lerp stands for Linear Interpolation
it essentially fills in the missing
it essentially fills in the missing
numbers between two values.
numbers between two values.
This creates a smoothmotion
This creates a smoothmotion
rather than jumping from one value to the next.
rather than jumping from one value to the next.
The lerp_angle() method needs 3 parameters:
The lerp_angle() method needs 3 parameters:
- The value to start from
- The value to stop at
- The amount to add each step
Gravity
Gravity
Use the built-in method to check if the player is on the floor.
Use the built-in method to check if the player is on the floor.
Simulate gravity pulling them down when they are not on
Simulate gravity pulling them down when they are not on
the floor.
the floor.
Jumping
Jumping
Testing shows that we can jump, fall back to ground and cannot jump while in the air
Testing shows that we can jump, fall back to ground and cannot jump while in the air
If player is on floor and pressing jump key
If player is on floor and pressing jump key
We let them jump (change their y velocity by jump force)
We let them jump (change their y velocity by jump force)
Resetting
Resetting
Create a game_over function
Create a game_over function
To reload the scene
To reload the scene
In the _physics_process function
In the _physics_process function
Check when the player falls off the platform
Check when the player falls off the platform
call the game_over function
call the game_over function
Drag the Player Node into the FileSystem to save it as it's own Scene
Drag the Player Node into the FileSystem to save it as it's own Scene
Alternatively right-click on it and select Save Branch as Scene
Alternatively right-click on it and select Save Branch as Scene