Video Game Design and Coding · PLECK lesson
PLECK lesson 62 · suggested week 13, day 2
Implement a grounded jump
Objective. Use is_on_floor and just-pressed input to restrict jumping.
Godot Engine Standard desktop editor 4.7.2-stable, GDScript (Godot 4), Compatibility renderer. Headless Godot 4.7.2.stable.official.ed1daf0bf passed 106 assertions on the supplied scaffolds, including malformed JSON saves. Audio used the Dummy driver and a synthetic WAV, not a speaker. The visual editor, browser export, and signed-in submission were not tested. The desk still does not run a student's own upload.
About 55 minutes. The due date is chosen by a parent.
Gravity, jumps, floor checks and safe geometry
Suggested pace: Recall and predict 5 min; Read instruction and scaffold 12 min; Build or design the assigned artifact 25 min; Run acceptance tests 8 min; Explain and checkpoint 5 min.
Materials: Godot Standard 4.7.2 desktop editor (GDScript, Compatibility renderer), Local course folder and prior checkpoint, No paid assets or public account required.
Comes after VGC-L061.
Build C-PLATFORM with a rectangular player collider and a StaticBody2D floor. _physics_process sets horizontal velocity, adds gravity when airborne, and applies the jump impulse only when jump is just pressed and the prior motion established floor contact. move_and_slide resolves the movement. Begin above the floor rather than overlapping it. Holding Space should not create repeated jumps in midair. A player can still jump again after landing and pressing again; this is a deliberate one-jump rule.
Worked example
A ball thrown upward begins with negative y velocity. Gravity adds a positive amount each physics step, slowing the rise and eventually producing downward motion. Scaffold C-PLATFORM — A gravity-and-jump platform player Setup: CharacterBody2D root Player, child CollisionShape2D RectangleShape2D size (24,32), no scale changes. Layer 1 mask 2. StaticBody2D floor layer 2 mask 1 with rectangular collider. Add Input Map move_left, move_right and jump bound to Space. Place player above floor, not intersecting it. Coordinates use positive y downward. Attach script to Player. ```gdscript extends CharacterBody2D @export var speed: float = 160.0 @export var gravity: float = 900.0 @export var jump_speed: float = 340.0 func _draw() -> void: draw_rect(Rect2(-12, -16, 24, 32), Color.SKY_BLUE) draw_line(Vector2(-8, -4), Vector2(8, -4), Color.BLACK, 2.0) func _physics_process(delta: float) -> void: velocity.x = Input.get_axis("move_left", "move_right") * speed if not is_on_floor(): velocity.y += gravity * delta if Input.is_action_just_pressed("jump") and is_on_floor(): velocity.y = -jump_speed move_and_slide() ```
A gravity-and-jump platform player
GDScript (Godot 4, not Scratch, Python, JavaScript or C#). Scaffold C-PLATFORM. Copy starts from this text. The desk does not run it.
Scene and node setup
CharacterBody2D root Player, child CollisionShape2D RectangleShape2D size (24,32), no scale changes. Layer 1 mask 2. StaticBody2D floor layer 2 mask 1 with rectangular collider. Add Input Map move_left, move_right and jump bound to Space. Place player above floor, not intersecting it. Coordinates use positive y downward. Attach script to Player.
extends CharacterBody2D
@export var speed: float = 160.0
@export var gravity: float = 900.0
@export var jump_speed: float = 340.0
func _draw() -> void:
draw_rect(Rect2(-12, -16, 24, 32), Color.SKY_BLUE)
draw_line(Vector2(-8, -4), Vector2(8, -4), Color.BLACK, 2.0)
func _physics_process(delta: float) -> void:
velocity.x = Input.get_axis("move_left", "move_right") * speed
if not is_on_floor():
velocity.y += gravity * delta
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = -jump_speed
move_and_slide()
Checks to run in the editor
- Player lands without sinking.
- Holding jump does not repeatedly jump in air.
- Do not multiply the whole velocity by delta before move_and_slide.
Native Godot 4.7.2.stable.official.ed1daf0bf headless compile and representative node-tree/runtime tests passed; see native-qa-results.json. Visual UI, audible output, exports and website submission still need separate checks.
Implement a grounded jump — evidence task
- 1. Build the player and one floor using C-PLATFORM.
- 2. Test tap, hold, airborne press and press after landing.
Deliverable. Platform baseline project and four-input test record.
Acceptance checks
- VGC-L062-T1. Only grounded just-presses start a jump.
- VGC-L062-T2. The player lands on top of the floor without sinking.
Understanding question. Why check is_on_floor rather than y velocity equal to zero?
Include a downloadable project ZIP with project.godot, .tscn, .gd and original asset files when code changes. A private, teacher-accessible download link to that ZIP is equivalent. Screenshots or a playthrough do not replace editable source.
If this is still shaky. Use C-PLATFORM with one wide floor and no hazards. Verify floor contact before adding platforms. Start with the first assigned task and re-run its acceptance test before adding the remaining feature.
Optional extra. Compare two gravity/jump-speed pairs while keeping horizontal speed fixed. Document one changed parameter, your prediction, and the observed effect; optional, not required for completion.
- Your first 2D game
Free public tutorial; no account; external asset download is optional, not used by this course.
· Opening this link does not submit the lesson.
Name ____________________ Date ____________________