User input

I'm running into a problem. It's not intractable but it was unexpected.

My physics sim rate is independent of my video frame rate. But my input is tied to the video frame rate. This creates a problem with physics are updated in the input processing.

For example, when a player pushes the jump button I apply and impulse to the active body and the bodies it's standing on. All is fine there. However my input get processed again before the physics engine. The jump button is still down, so the impulse is applied again. Do that a couple of times then the physics if finally simulated. What was a reasonable impulse is now 4 times that.

How is everyone else solving this?

My methods. First, an on press event works for jump but not for left / right movement where the force must be continually reapplied.
Currently, I check in the update to see if the world_has been stepped. If it has since last input update the force is applied, otherwise it is ignored. This causes a delay from when the button is pressed to when it gets simulated. Will the delay be noticeable, is questionable, but it feels wrong to purposely delay input.

I was thinking about building a motor system on top of box2d that allowed me to set up a force, impulse or torque to be applied every simulation step. Has anyone gone this route? It seems a bit overkill but I can't see how else to do it.

-nick
It sounds like you're processing input events... that's usually a non-deterministic solution as you're at the mercy of the event thread. I prefer to poll the state of the input device (keyboard, mouse, joystick, etc) when I need to. Then you process when you want, and how many times you want.

Bill

Original thread: https://box2d.org/forum/viewtopic.php?t=715