GDScript Fundamentals

Lesson 7 of 7

Final Project: Player Movement Script

Combine everything from this course into a real, playable script: 2D platformer-style player movement, the foundation almost every 2D Godot game starts from.

Requirements

  1. Create a script extending CharacterBody2D with @export variables for speed and jump_velocity, tunable from the editor's Inspector.
  2. In _physics_process(delta), read left/right input and set horizontal velocity accordingly (use Input.get_axis("ui_left", "ui_right") or your own custom input actions).
  3. Apply gravity to vertical velocity every frame, and let the player jump (set a negative vertical velocity) only when is_on_floor() is true, so jumping mid-air isn't possible.
  4. Call move_and_slide() to actually apply the computed velocity and handle collisions.
  5. Define a signal health_depleted and a simple health variable with a take_damage(amount) method that emits the signal when health reaches 0, connect to it from a separate script (even a simple one that just prints "Game Over") to prove the decoupling works.

Stretch goals

  • Add a Sprite2D reference and flip it horizontally based on movement direction.
  • Add a double-jump, allowed only once per airborne period.
  • Add a @export var coyote_time: float grace period that still allows a jump for a few frames after walking off a platform edge.

Submit a link to your finished project below, an instructor will review it before you can mark this lesson complete. Good luck!

This lesson ends in a project. Build it on your own machine, there's nowhere to submit it here, but the brief above is everything you need.