LESSON 2 OF 6

Give the courier controlled movement

Use input actions, a speed in pixels per second, and CharacterBody2D movement without a diagonal speed boost.

Godot 4.7.2 stable · standard edition · GDScript · 20 minutes estimated practice
0 of 6 lessons completeGuest progress stays in this browser. Account progress is separate.

Continue your working project from the previous lesson. Each download is the completed version of this lesson, for recovery and comparison. Start lesson one with checkpoint 01.

Continue from the room

Use your lesson-one working folder, or extract checkpoint 01 into a fresh working folder. Checkpoint 02 is the completed comparison for this lesson. Stop the running game before editing.

The courier already has a collision shape and floating motion mode. In this lesson it moves through an open room; the wall boundaries arrive in lesson three.

Replace the movement function

Open player.gd. Leave extends CharacterBody2D, const SPEED := 180.0 and _draw() in place. Replace the whole _physics_process function with the code below. Keep the indentation shown.

Input.get_vector combines the built-in directional actions and limits the vector’s length, so pressing two directions does not give a faster diagonal. velocity is in pixels per second. move_and_slide uses the physics step internally, so this velocity assignment does not multiply by delta.

  1. Save player.gd and press F5. Move with the arrow keys.
  2. Compare moving right with moving right and down together. Release all keys and check that movement stops.
  3. If the courier leaves the visible room in this checkpoint, stop and run again. The next lesson gives the room physical boundaries.
func _physics_process(_delta: float) -> void:
	velocity = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down") * SPEED
	move_and_slide()

Make a measured speed experiment

With the game stopped, change SPEED from 180.0 to 120.0. Run it and compare the time needed to cross a similar distance. Restore 180.0 before moving to the next lesson.

The useful question is whether a particular speed makes the route comfortable. Record what you observed instead of assuming a larger number improves the game.

OBSERVE THE RESULT

Check your work.

  • Each arrow key moves in the expected direction.
  • Diagonal movement feels comparable to straight movement.
  • Releasing all direction keys stops the courier.
  • Restoring SPEED to 180.0 restores the original setting.
This is self-reported practice, not a qualification.

If something went wrong.

  • Replace the existing _physics_process function instead of adding a second function with the same name.
  • Use all four action names exactly: ui_left, ui_right, ui_up and ui_down.
  • Multiplying velocity by delta here makes movement much slower because move_and_slide already uses the physics step.
TAKE THE CONTEXT TO YOUR OWN CHATGPT

Ask about one small step.

I am using Godot 4.7.2 and the One Small Delivery movement checkpoint. My CharacterBody2D uses Input.get_vector and move_and_slide. Help me understand the relation between direction, velocity, speed and the physics step. Work from my current player.gd, suggest one small experiment, and give a check for straight, diagonal and released-key behavior.

Source notes & checks.

Checked November 14, 2026 with Godot 4.7.2.stable.official.ed1daf0bf: all six checkpoints passed headless parser/import and 53 engine runtime checks, including actual movement and wall collision, interaction distance, single delivery and restart signal/handler behavior. Six packaged ZIP hashes were checked. Headless tests do not establish editor usability, rendered appearance, physical keyboard/mouse behavior, exported builds, mobile support or compatibility with other engine versions.

Original workshop project code and placeholder shapes are provided under the MIT license. Keep LICENSE.txt with redistributed source. Godot is distributed separately under its own license.

Workshop edition 1.0.0. Source and checkpoint downloads are free.