Exact rerun of a physical simulation

Started by
4 comments, last by MAXXC 20 years ago
I''m writing a small physics engine that must have one important feature: If I restart the simulation (e.g. some objects with initially velocity that jump around on a plane) it must produce the same result, even after 30 seconds all objects should be in the exact same place. I already searched this forum and google and had a look at the different numerical integrators (Euler, RK, ...), but I think this is not the problem. After doing some tests I realized my problem is the variable time step based on the elapsed time. Even RK4 has problems producing the same result. But if I use a fixed time step the result will always be the same while using one of the integrators. I my case it is not important to get very accurate results it is only important that a rerun produces the same result. My question is, is it possible to use a variable time step to adapt to different frame rates or should I stay with a fixed time step and save myself a lot of trouble? Thank you, Max
Advertisement
sure is.

you need to store the initial state (obviously), and the inputs to the physics system every frames. that includes the variable timestep, things like player controls, use of a deterministic random number generator, ect... the problem is, you either get a perfect result, or you don''t, because even after a second, the results will diverge significantly. As for debugging, you can store state the of the physics system every 20 frames or so, in a compress form, and check if the rerun is consistent with that, because otherwise, it will be incredibly difficult to debug is somethings goes wrong.

Console replay features works like this. You may have trouble running an identical simulation on different platform, depending on the way the floating point arithmetics is done on different CPUs.

Everything is better with Metal.

There is one important thing I forgot: once the simulation is running there are no user inputs.

And by rerun I mean a rerun of the whole system, not only a reproduction of the previous run. That''s important, because the player can adjust one of the parameters and only the parameter should produce a change in the run, not an instability in the simulation / integrator.

The problem with the floating point arithmetics won''t exist, because the reruns only have to be the same on the current system.

To name it I''m trying to do a game like the original incredible machine games.


Max

It''s a frequent problem. Simply use a fixed timestep for your physics. You can still keep a variable time step in the display, by interpolating between the "physic steps".

Google for variable "time steps game loop physic". It should turn up some good results.
Use what Cedric suggested. All game logic is done at a fixed framerate. If there are frames between these "keyframes" you calculate them by interpolating the key frames. This is the same kind of system that is used to keep sync in many multiplayer games.
yeah, in that case, run the physics at a constant FPS, and catchup / interpolate the rerun of the simulation.

you can even store the timesteps in a list, and use them in the rerun, but you''ll still need some interpolation as suggested above, because it''s unlikely the framerate of the rerun will be identical to the framerate of the simulation.

Everything is better with Metal.

This topic is closed to new replies.

Advertisement