---
name: coyote-time-jump-buffer
description: Implement responsive 2D/3D platformer jumping with Coyote Time (85–145ms post-ledge grace), Jump Input Buffer (100–150ms pre-landing queue), Variable Jump Cut, and Ledge Edge Nudge so players never lose cliff jumps to frame-exact input jitter.
---

# Coyote Time & Jump Input Buffer (EP32)

## Core Problem: Why Raw `if (isGrounded && jumpPressed)` Feels Broken
When AI coding agents implement platformer jumping naively (`if (isGrounded && jumpPressed) vy = JUMP_VEL`), players fail **50%+** of fast cliff jumps:
1. **Late cliff press (+20ms to +100ms after leaving edge)**: Visually the character's toes just left the cliff, so the player expects a jump — raw `isGrounded` is already `false`, eating the input and dropping the player straight into the chasm.
2. **Early landing press (-20ms to -110ms before touchdown)**: Players instinctively tap Jump a few frames before their feet touch the ground for continuous platforming flow — raw code discards the tap, forcing an awkward flat run off the next ledge.

## 4 Production Rules (Ship-Ready Platformer Feel)

1. **Rule 01 — Coyote Time Timer (`coyoteWindowMs = 85..145ms`, Celeste default `110ms`)**:
   - While `grounded === true`, reset `coyoteTimerMs = coyoteWindowMs` and `hasJumpedThisAirborne = false`.
   - Once airborne without jumping, count down `coyoteTimerMs -= dtMs`.
   - Allow jumping whenever `(grounded || coyoteTimerMs > 0) && !hasJumpedThisAirborne`, immediately resetting `vy = JUMP_VEL` (clearing any downward fall velocity!) and setting `coyoteTimerMs = 0` so players can never double-jump inside the grace window.
2. **Rule 02 — Jump Input Buffer (`jumpBufferMs = 100..150ms`, Celeste default `120ms`)**:
   - On every Jump button press, set `jumpBufferTimerMs = jumpBufferMs`, then count down `jumpBufferTimerMs -= dtMs` each tick.
   - Whenever `(grounded || coyoteTimerMs > 0) && jumpBufferTimerMs > 0`, fire the jump immediately on frame 1 of touchdown and clear both timers (`jumpBufferTimerMs = 0`, `coyoteTimerMs = 0`).
3. **Rule 03 — Asymmetric Gravity + Variable Jump Cut (`vy *= 0.48`)**:
   - Apply heavier gravity on descent (`gravityFall ≈ 1.2× gravityRise`) so jumps feel crisp instead of floaty.
   - On early button release while rising (`vy < -140`), scale `vy *= 0.48` for surgical short-hop control.
4. **Rule 04 — Ledge Edge Nudge (`6..12px`)**:
   - If the player's feet graze within `edgeNudgePx` below a far platform's top lip while moving horizontally toward it, smoothly snap/mantle them up onto the top surface instead of bonking their shins into the abyss.

## Minimal Engine Reference (Godot 4 / Unity C# / TypeScript)

```ts
// Fixed-timestep 60Hz update
if (grounded) {
  coyoteTimerMs = COYOTE_WINDOW_MS; // 110ms
  hasJumped = false;
} else {
  coyoteTimerMs = Math.max(0, coyoteTimerMs - dtMs);
}

if (jumpJustPressed) {
  jumpBufferTimerMs = JUMP_BUFFER_MS; // 120ms
} else {
  jumpBufferTimerMs = Math.max(0, jumpBufferTimerMs - dtMs);
}

if (jumpBufferTimerMs > 0 && coyoteTimerMs > 0 && !hasJumped) {
  vy = JUMP_VELOCITY; // Reset downward velocity cleanly!
  coyoteTimerMs = 0;
  jumpBufferTimerMs = 0;
  hasJumped = true;
}

if (jumpJustReleased && vy < -140) {
  vy *= 0.48; // Variable jump height cut
}
```

## Verification Checklist
- [ ] Pressing Jump `+65ms` after walking off a cliff clears the chasm with `coyoteWindowMs = 110ms` and falls with `0ms`.
- [ ] Pressing Jump `-75ms` before touching ground triggers a frame-1 bounce jump with `jumpBufferMs = 120ms` and is eaten with `0ms`.
- [ ] Triggering a Coyote Jump zeroes `coyoteTimerMs` immediately so no accidental double-jump occurs.
- [ ] Across a 200-trial human-jitter test (`-55ms..+105ms`), Production config clears `>= 90%` vs `< 50%` for naive `0ms` checks.
