Today I learned
How do I stop a one-shot input from firing on every fixed-timestep step?
In a fixed-timestep sim a frame can run 0, 1 or 4 physics steps. A "pressed" flag (jump, drop, interact) that you simply overwrite each frame gets lost on a 0-step frame. So you OR it into the pending input instead, and clear it after the first step that reads it. My bug: drop was in the merge but missing from the clear, so one press of X kept dropping everything the player picked up afterwards.
The fix is to keep one list of one-shot fields and derive both the merge and the clear from it, so adding a new action can't break either:
const ONE_SHOTS = ['jump', 'drop', 'interact', 'yank'] as const
// on every input message from a client (can arrive several times per step)
function mergeInput(pending: Input, next: Input): Input {
const out = { ...next }
for (const k of ONE_SHOTS) out[k] = pending[k] || next[k]
return out
}
// at the end of each physics step
function consumeOneShots(i: Input) {
for (const k of ONE_SHOTS) i[k] = false
}
Held inputs (move axes, "reel while held") stay out of the list and are just overwritten. Add a headless regression test: press once, step for half a second, then check the next pickup stays in hand.
Hit this in a host-authoritative co-op prototype (Rapier, 60 Hz steps, up to 4 per frame).
Background on fixed timesteps: https://gafferongames.com/post/fix_your_timestep/