Video Game Design and Coding · PLECK lesson

PLECK lesson 14 · suggested week 3, day 4

Move by speed times elapsed time

Objective. Explain delta and prevent faster diagonal travel.

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.

A visible actor, reusable scenes and measured movement

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

A game draws many frames each second, but frame duration varies. Moving a fixed pixel count each frame makes a faster computer move farther each second. C-FREE-MOVE multiplies speed in pixels per second by delta in seconds. Input.get_vector combines four actions and limits length to one, preventing diagonal movement from becoming faster. Read the code as units: pixels/second times seconds equals pixels. This free-moving actor is not a physics body and cannot stop against a wall.

Worked example

A circle drawn at Vector2.ZERO belongs to its Node2D origin. If its parent is at (100,80) and its local position is (20,10), its world origin is (120,90) when neither parent is rotated or scaled. Scaffold C-FREE-MOVE — Frame-independent movement without collisions Setup: Use Node2D root Actor, attach this script in place of C-DRAW. Project Settings > Input Map: add move_left, move_right, move_up, move_down. Bind A/Left, D/Right, W/Up, S/Down respectively using physical key events. Project Settings > Display > Window: viewport width 640 height 360. Local Actor has no transformed parent. This version moves but cannot collide with walls. ```gdscript extends Node2D @export var speed: float = 160.0 func _draw() -> void: draw_circle(Vector2.ZERO, 14.0, Color.CORNFLOWER_BLUE) draw_line(Vector2(-8, 0), Vector2(8, 0), Color.WHITE, 3.0) func _process(delta: float) -> void: var direction := Input.get_vector("move_left", "move_right", "move_up", "move_down") position += direction * speed * delta position.x = clampf(position.x, 14.0, 626.0) position.y = clampf(position.y, 14.0, 346.0) ```

Frame-independent movement without collisions

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

Scene and node setup

Use Node2D root Actor, attach this script in place of C-DRAW. Project Settings > Input Map: add move_left, move_right, move_up, move_down. Bind A/Left, D/Right, W/Up, S/Down respectively using physical key events. Project Settings > Display > Window: viewport width 640 height 360. Local Actor has no transformed parent. This version moves but cannot collide with walls.

extends Node2D
@export var speed: float = 160.0
func _draw() -> void:
    draw_circle(Vector2.ZERO, 14.0, Color.CORNFLOWER_BLUE)
    draw_line(Vector2(-8, 0), Vector2(8, 0), Color.WHITE, 3.0)
func _process(delta: float) -> void:
    var direction := Input.get_vector("move_left", "move_right", "move_up", "move_down")
    position += direction * speed * delta
    position.x = clampf(position.x, 14.0, 626.0)
    position.y = clampf(position.y, 14.0, 346.0)

Checks to run in the editor

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.

Move by speed times elapsed time — evidence task

  1. 1. Replace Actor script with C-FREE-MOVE and run as a single actor.
  2. 2. Measure rightward travel for roughly one second and compare diagonal distance.

Deliverable. Moving Actor project and measurement note.

Acceptance checks

Understanding question. Why would position += direction * speed without delta be frame-dependent?

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 a 640 by 360 viewport, one unscaled Node2D and the C-DRAW recipe before adding movement. Start with the first assigned task and re-run its acceptance test before adding the remaining feature.

Optional extra. Add a second independently colored actor without changing the first actor’s script. Document one changed parameter, your prediction, and the observed effect; optional, not required for completion.

Name ____________________ Date ____________________