Player Script

Add a Script to the Player Node.

Call it Player



Remove all generated code except the first line.

Input Map

Click on:

 Project --> Project Settings --> Input Map

Name your action move_forward


Click on Add

Now click on the + symbol

Godot is listening for input.

Press the key you want to use to move the player forward (W)

W on the keyboard is now the forward key.

Follow the same process for backwards (S), left (A), right (D) and jump (SPACE).

Variables

Set up variables for move_speed, jump_force and gravity

We also need to position the camera as the player moves.

Add a variable to track the angle the player is facing.

To rotate the Player Model we need an instance of it stored in a variable.

We use the @onready annotation so that the variable is loaded when the scene is ready.

We get the node named Model and store it in our MeshInstance3D variable 

Which we have named "model"

Creating the Player Movement

To move the player we will use the _physics_process method instead of _process

_physics_process runs at a constant rate every second

whereas _physics runs every frame.

Use built-in method get_vector to find out which direction player is moving based on their key presses.

Now store the Player's x, y and z direction in a new Vector3 variable:

Note that get_vector returns a 2-dimensional vector (x and y only).

The player only needs to move on the x and z axes

So we set the y value to 0 and use the y value from get_vector for z

Now set the built-in velocity variable to the value of our dir vector.

Call the move_and_slide method to run the players movement methods.

Test

We can move around with our keys but: