This project has moved and is read-only. For the latest updates, please go here.

fixed timestep interpolation

Topics: Developer Forum
Jan 6, 2013 at 6:00 PM

hi there,

i was wondering if someone implemented the technique from gaffers fix your timestep article using farseer. he writes about interpolating between last & current frame, do you copy the physics state to a render state? if so, isn't that too much overhead?



Jan 7, 2013 at 3:42 PM

It does cause overhead but define what's "too much"? Doing a few (thousand) calculations is nothing on a modern CPU or even mobile even if every frame. What you should be careful, instead, is garbage - especially on mobile/consoles. A rule of thumb is "Don't make garbage!" :) Garbage collection is furthermore unpredictable so it will just happen at the worst possible time.

If you use XNA note that it already has a fixed time step implementation (IsFixedTimeStep=true).

More info here:

For another example the Unity3D game engine (which runs on mono) has a FixedUpdate implementation built-in as well since it's such a fundamental technique in game physics. 

Basically you should always use a fixed time step - it's a necessary evil even if there is overhead. The alternative is often worse and might lead to unstable physics. Humans don't like unstable (jittery) physics because we reject it on a subconscious level whereas we might tolerate other imprecision better.

Gaffer's method is just one implementation for a generic game engine which can be applied to XNA when IsFixedTimeStep=false. But there is even more you can do with state buffering and intra/extrapolation without even going into determinism and networking. Check this for example for an extremely in-depth solution to multithreading the game loop that uses a triple-buffered physics state with an attempt at minimal locking:

Jan 7, 2013 at 6:42 PM

hi jerry,

thanks! i probably should have mentioned it's for a pretty big simulation (with thousands of objects, not all active at once ofcourse). so duplicating all those states each frame sounds like much overhead. now i think of it i could just copy only the objects visible for the interpolation part ofcourse.. i was hoping there would be any implementations of this technique since everyone talks about it, but concrete implementations seems to be lacking :s

the triple-buffer technique sounds interesting, but it seems like he is extrapolating, which sounds worse as interpolation to me. i guess the render would render objects going through other objects at times it lacks physics update, with interpolation you get a little bit lag, but should be more consistent.

Jan 7, 2013 at 10:47 PM

But if you offload the physics and rendering to different threads you basically get them "free" since everything nowadays is multicore from phones to consoles to PCs...

Extrapolation can indeed lead to artifacts but at a high frequency of updates they will be probably imperceptible because the update will soon provide fresh data to correct the problem.  Interpolation has its own set of problems notably the artificial lag it creates even though that's more visible in networking. I guess there is no silver bullet.