thedivergentai/godot-game-loop-time-trial
Expert patterns for racing mechanics, checkpoint tracking, and ghost recording/playback in Godot 4. Use when building racing games, speed-run platformers, or arcade trials.
npx skills add https://github.com/thedivergentai/GD-Agentic-Skills --skill godot-game-loop-time-trial
> [!NOTE]
> Resource Context: This module provides expert patterns for Time Trial Loops. Accessed via Godot Master.
A Master implementation treats Time Trials as a State-Validated Sequence. Recording a time is easy; ensuring the player didn't cheat via shortcuts requires a strictly ordered CheckpointManager.
Prevent "Shortcut Cheating" by requiring checkpoints to be cleared in numerical order.
Wire Area body_entered (physics) → TimeTrialManager.pass_checkpoint(index). The manager owns usec timing — see script.
Sample at a fixed rate (e.g. 10 Hz). Lerp position; slerp Quaternion rotation (ghost_recorder.gd / ghost_replayer.gd). Never Euler-lerp ghost heading.
| Format | Best For | Implementation |
| :--- | :--- | :--- |
| Dictionary Array | Prototyping | Simple [{t: 0.1, p: pos}, ...] |
| Typed Array | Performance | PackedVector3Array for positions. |
| JSON/Binary | Saving | FileAccess.get_var() to save ghost files. |
Time.get_ticks_usec() for microsecond precision._physics_process() to guarantee detection within the fixed physics step.await get_tree().physics_frame before checking for players.BoxShape3D.size) instead.ENetMultiplayerPeer with TRANSFER_MODE_UNRELIABLE for high-frequency position updates.multiplayer.is_server() to prevent cheating.is_equal_approx() to account for precision loss in accumulated time variables.Input.flush_buffered_events() to ensure the engine has processed the latest raw input.PackedVector3Array to maintain a contiguous memory block.@onready to cache node references during initialization.Player physics layer to minimize the number of physics overlap calculations.slerp() or Quaternion.slerp() to avoid gimbal lock and ensure smooth rotation interpolation.> MANDATORY: Follow the golden path order. Read each listed script before coding that stage.
time_trial_manager.gd — microsecond (Time.get_ticks_usec) or physics-frame clock; pass_checkpoint only from physics overlaps / Area signals_process)ghost_recorder.gd — samples {t, p, q} with Quaternion rotationghost_replayer.gd — position lerp + Quaternion slerp (never Euler lerp)time_trial_leaderboard_bridge.gd — integer usec/msec → UI strings10 Expert patterns: Microsecond timing, server-authoritative validation, rubber-banding AI, and frame-perfect input flushing.
Central clock. Accumulates Time.get_ticks_usec() (or physics-frame counts). Finish checks must come from physics overlaps.
Captures transform samples with Quaternion "q" fields for slerp-safe playback.
MANDATORY with recorder. Replays samples via position lerp + Quaternion.slerp.
Jitter-buffer for smooth ghost playback during network streaming.
Formatting utility for converting raw time data to human-readable strings.
Store a keyframe only when position/rotation changes beyond a threshold. Persist with FileAccess.open_compressed() + ZSTD; prefer binary floats over JSON.
Store records as int usec/msec. Format with %02d:%02d.%03d for stable UI (e.g. 01:24.450).
> LLM-ignorance rule: If a general agent would not know it before reading, load the reference — never delete expert deltas.
> Progressive disclosure: open Official Documentation links only when researching a specific API; load Related Skills when routing to a peer domain — do not preload the whole lattice.
get_ticks_usec() for microsecond lap clocks when OS.get_ticks_msec() is too coarse for race records._physics_process, not visual _process frames that can skip under load.body_entered for ordered checkpoint gates without scanning every physics body.BoxShape3D.size) instead of non-uniform CollisionShape3D scale so SAT stays valid on gates.slerp() between keyframes so ghost heading avoids gimbal lock from naive Euler lerp.interpolate_with() for jitter-buffered network ghost playback between ordered frames.FileAccess / store_var patterns for persisting ghost runs and best-time dictionaries without float display round-trips.TRANSFER_MODE_UNRELIABLE for high-frequency racer transforms where TCP-style reliability spikes latency.flush_buffered_events() when frame-perfect boost/stop must see the latest raw input before the physics step.physics_ticks_per_second / get_physics_frames() for integer frame-count timing bridges into MM:SS.mmm UI.TimeTrialManager and checkpoint Areas into a track scene.await physics_frame, and RPC annotations used in timing and authority patterns.Take thedivergentai/godot-game-loop-time-trial from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.