Our Script will control the player.

Click Player and create a new script.

Save it as Player.gd

By default, Godot creates code to move a player 

for scripts that inherit from CharacterBody2D. 

For this lesson, we are going to delete everything 

except line 1:

Inside the script, we will create a function called _physics_process. 

This function gets called at a consistent rate per second.

Now we don’t need to use the delta time

value for moving the player. 

As discussed in the Delta section.

In the function, we will detect keyboard inputs

 and modify our velocity based on that. 

To do this, we will start by setting 

the velocity to zero on both axes.

Use If statements to change velocity for each different key press








Call the move_and_slide() function for physics calculations behind the scenes.

Player Speed


If you test now the player moves SO SLOWLY you would think the code is not working!

Multiply velocity by 300 before calling move_and_slide()

Test again.

A better way to control speed is to use a variable.

Create a speed variable at the top of the script.

Call it moveSpeed.








Then multiply velocity by moveSpeed.