Repeating Game Input Fails

Update and DeltaTime vary too much, is there a way to have deterministic gameplay by recording user input and feeding it back into the game (assuming no randomness elsewhere)

I’m writing an app that records user input sent to the game and then allows for a replay feature by resending the input as it was received. This is resulting in inaccurate playback where the player loses in the reply before where they actually lost.

Any advice on how I can achieve this? Below is a simple example of my use-case that isn’t working.

[GAME STARTS] TimeElapsed = 0
[UPDATE 1] Update(dt), dt = 0.05, -> TimeElapsed += dt
[USER CLICKS] RecordInput at TimeElapsed, or 0.05
[UPDATE 2] Update(dt), dt = 0.043, -> TimeElapsed += dt

[APP LOADS INPUT DATA] Known input = at dt 0.05, action = Click
[GAME STARTS] TimeElapsed = 0
[UPDATE 1] Update(dt), dt = 0.045, -> TimeElapsed += dt
[UPDATE 2] Update(dt), dt = 0.057, -> TimeElapsed += dt -> [ALERT APP]
[APP CHECKS INPUT DATA], finds input at 0.05, -> [APP CLICKS]
[ERROR] RecordInput, at TimeElapsed, so 0.057, was supposed to occur at 0.05

A real example (these are the incremented delta time values (TimeElapsed) sent to my app by Update):
FRAME PLAYING = 9.402000000000006
FRAME PLAYING = 9.702000000000005
FRAME PLAYING = 10.002000000000004
FRAME PLAYING = 10.219000000000003
[User had clicked at: 10.619] but this wasn’t called because the next time update was called was: FRAME PLAYING = 10.783999999999983

Notice how each call to update varies wildly (update could be called between 2-10 times per second). That’s the difference between life and death in my game so input needs to be exact.

Is there any better way to achieve my goals with exact precision?


You can’t do that using that deltaTime, the time has passed since the last frame has been rendered.

The time it takes to render a frame can vary a lot, even if all of your game input parameters are the same. It can be affected by the OS, other applications/browser tabs using the CPU/GPU etc.

To do a replay method you would have to decouple all of your animations/translations from the deltaTime and bind them to a fixed update cycle of yours. This should happen both during gameplay time, when you record your input and when you play it back on replay time.

Here is a helpful page on how to achieve a steady and fixed FPS:

1 Like

I was literally trashing the replay system and was going to just record the app’s screen instead, but this link made me realize how easy it would be. Really appreciate it!

Yeah this is like undo/redo, common app required features which can be just a button on the surface but they require a whole new perspective of how you do things to implement.

1 Like