Skip to content

Today I learned

How do I stop a one-shot input from firing on every fixed-timestep step?

· updated #Game development

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:

ts
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/

The 30-second version

Share LinkedIn Post on X

Related notes

Newsletter

Occasional notes on engineering, game tech, and new tools — no spam, unsubscribe anytime.

Ravy

Engineering manager, founder, and software developer building web platforms, game systems, real-time services, and automation tools. 15 years of shipped work — currently at Gaijin.net.

Get in Touch

Building an MVP, shipping a game feature, or automating a team workflow? Open source or paid — let's talk.

Contact Me
© 2020-2026 XPLOIT FZE. All trademarks, names and logos belong to their respective copyright holders.