Video Game Design and Coding

PLECK lesson 68 · suggested week 14, day 3

Make collision feedback trustworthy

Objective. Separate solid platforms, sensors and decorative objects.

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.

Progress markers, camera framing, collision feedback and limited forgiveness

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-L067.

Players infer rules from repeated visual patterns. A solid platform should look consistently solid, while a background decoration should not unexpectedly block movement. Label your node categories: StaticBody2D for solid floor, Area2D for checkpoint or goal, Node2D visuals for decoration. Match collider boundaries to artwork and remove tiny invisible lips at joins. Test walking slowly along platform seams and jumping against undersides. A collision issue that looks like poor jumping may actually be misaligned geometry.

Worked example

A checkpoint trigger and safe spawn marker serve different roles. The trigger notices arrival, while the marker specifies a collision-free return location above a platform. 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() ``` Scaffold C-CHECKPOINT — A safe checkpoint respawn Setup: Add this pattern to a separate Node2D level root with child Player using C-PLATFORM. Call set_checkpoint with a safe global position when a player reaches a checkpoint Area2D; call respawn when entering a fall zone. This code does not connect Area2D automatically; select the area body_entered signal in editor and call these methods from its handler after checking the player group. Respawn is deferred because a physics callback may be active. ```gdscript extends Node2D @onready var player: CharacterBody2D = $Player var checkpoint: Vector2 func _ready() -> void: checkpoint = player.global_position func set_checkpoint(safe_position: Vector2) -> void: checkpoint = safe_position func respawn() -> void: _apply_respawn.call_deferred() func _apply_respawn() -> void: player.global_position = checkpoint player.velocity = Vector2.ZERO ```

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.

A safe checkpoint respawn

GDScript (Godot 4, not Scratch, Python, JavaScript or C#). Scaffold C-CHECKPOINT. Copy starts from this text. The desk does not run it.

Scene and node setup

Add this pattern to a separate Node2D level root with child Player using C-PLATFORM. Call set_checkpoint with a safe global position when a player reaches a checkpoint Area2D; call respawn when entering a fall zone. This code does not connect Area2D automatically; select the area body_entered signal in editor and call these methods from its handler after checking the player group. Respawn is deferred because a physics callback may be active.

extends Node2D
@onready var player: CharacterBody2D = $Player
var checkpoint: Vector2
func _ready() -> void:
    checkpoint = player.global_position
func set_checkpoint(safe_position: Vector2) -> void:
    checkpoint = safe_position
func respawn() -> void:
    _apply_respawn.call_deferred()
func _apply_respawn() -> void:
    player.global_position = checkpoint
    player.velocity = Vector2.ZERO

Checks to run in the editor

  • A fall returns to last safe point, not origin.
  • Player has no leftover falling velocity on return.

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.

Make collision feedback trustworthy — evidence task

  1. 1. Audit every level object’s role and collider.
  2. 2. Test platform seams, side contacts and undersides with visible collision shapes.

Deliverable. Collision-role table and repaired level checkpoint.

Acceptance checks

  • VGC-L068-T1. Decoration does not block movement.
  • VGC-L068-T2. No hidden collider edge catches the player at a seamless-looking join.

Understanding question. Why should a checkpoint use a sensor instead of a wall body?

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 one checkpoint on a broad platform and keep the camera fixed until respawn is reliable. Start with the first assigned task and re-run its acceptance test before adding the remaining feature.

Optional extra. Compare start-only retries with a midpoint checkpoint using the same route. Document one changed parameter, your prediction, and the observed effect; optional, not required for completion.

Turn in typed notes and a JPEG, PNG, or WebP screenshot. One https address is stored as text and is not opened, extracted, or run. An MP3, WAV, M4A, MP4, or WebM file up to 4 MB can show a demo. The demo does not replace editable source. Zip and code files are refused. If there is no private link, keep the project on the family computer and review the code in person.

  • 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.

This is a preview. A parent assigns the lesson and chooses the due date after the student is enrolled. The answer key is not on this page.

Print this lesson