Godot game loop time trial

From thedivergentai/GD-Agentic-Skills · View interactive version

Godot game loop time trial is an AI agent skill from the GitHub repository thedivergentai/GD-Agentic-Skills. 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.

How to use this skill

Skill file

Architectural Thinking: The "Validation-Chain" Pattern

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.

Core Responsibilities

Expert Code Patterns

1. Robust Checkpoint Validation

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.

2. Space-Efficient Ghosting

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.

Master Decision Matrix: Data Storage

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

NEVER Do


Available Scripts

MANDATORY: Follow the golden path order. Read each listed script before coding that stage.

Golden path (MANDATORY)

  1. time_trial_manager.gd — microsecond (Time.get_ticks_usec) or physics-frame clock; pass_checkpoint only from physics overlaps / Area signals
  2. Checkpoint Areas — ordered indices into the manager (physics frame, not _process)
  3. ghost_recorder.gd — samples {t, p, q} with Quaternion rotation
  4. ghost_replayer.gd — position lerp + Quaternion slerp (never Euler lerp)
  5. time_trial_leaderboard_bridge.gd — integer usec/msec → UI strings

Script index

[time_trial_patterns.gd](scripts/time_trial_patterns.gd)

10 Expert patterns: Microsecond timing, server-authoritative validation, rubber-banding AI, and frame-perfect input flushing.

[time_trial_manager.gd](scripts/time_trial_manager.gd)

Central clock. Accumulates Time.get_ticks_usec() (or physics-frame counts). Finish checks must come from physics overlaps.

[ghost_recorder.gd](scripts/ghost_recorder.gd)

Captures transform samples with Quaternion "q" fields for slerp-safe playback.

[ghost_replayer.gd](scripts/ghost_replayer.gd)

MANDATORY with recorder. Replays samples via position lerp + Quaternion.slerp.

[time_trial_playback_buffer.gd](scripts/time_trial_playback_buffer.gd)

Jitter-buffer for smooth ghost playback during network streaming.

[time_trial_leaderboard_bridge.gd](scripts/time_trial_leaderboard_bridge.gd)

Formatting utility for converting raw time data to human-readable strings.


Expert Time Trial Patterns

1. Delta-Compression for Ghosts

Store a keyframe only when position/rotation changes beyond a threshold. Persist with FileAccess.open_compressed() + ZSTD; prefer binary floats over JSON.

2. The Leaderboard Bridge

Store records as int usec/msec. Format with %02d:%02d.%03d for stable UI (e.g. 01:24.450).

Expert knowledge (on demand)

LLM-ignorance rule: If a general agent would not know it before reading, load the reference — never delete expert deltas.

Reference

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.

Official Documentation

Related Skills

Prerequisites
Complements
Downstream / consumers
Master
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.