Godot game loop time trial

From nix-community/nur-combined · View interactive version

Godot game loop time trial is an AI agent skill from the GitHub repository nix-community/nur-combined. 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

Time Trial Loop: Arcade Precision

[!NOTE]

Resource Context: This module provides expert patterns for Time Trial Loops. Accessed via Godot Master.

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.

# time_trial_manager.gd snippet
func pass_checkpoint(index):
    if index == current_checkpoint_index + 1:
        current_checkpoint_index = index
        _emit_split_time()

2. Space-Efficient Ghosting

Avoid recording every frame. Sample the player's position at a fixed rate (e.g., 10Hz) and use Linear Interpolation (lerp) during playback to fill the gaps.

# ghost_replayer.gd (Conceptual)
func _process(delta):
    # Uses linear interpolation for smooth 60fps+ playback from 10hz data
    var target_pos = frame_a.p.lerp(frame_b.p, weight)

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: Read the appropriate script before implementing the corresponding pattern.

[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)

The central clock. Validates checkpoint order and handles "Best Lap" logic.

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

Captures high-frequency transform data for playback.

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.