One resolution for this downside utilized by some engines is to have physics updates be frame-independent.
For instance, the Unity engine makes use of a hard and fast physics timestep which is unbiased of rendering. These updates don’t really occur on a hard and fast real-time schedule; somewhat, when getting ready a brand new body for rendering, the engine checks how a lot time has elapsed for the reason that final physics replace, and runs the suitable variety of physics steps. Say that the physics engine is utilizing the default interval of 20 ms (50 updates per second). The engine is beginning a body. If it has been 65 ms for the reason that earlier body, then 3 physics updates are run sequentially. If it is solely been 10 ms for the reason that earlier body, then no physics replace happens.
Utilizing a hard and fast, frame-independent physics timestep offers us a extra constant simulation expertise that’s unaffected by framerate. Nonetheless, there’s an vital caveat, as illustrated within the final sentence of the earlier paragraph – if the rendering framerate is any larger than the replace fee, then the 2 techniques will probably be out of sync, and generally frames will render wherein nothing that makes use of physics has moved. If the rendering and physics are barely out of sync, we’ll discover occasional stutter. If rendering is way sooner than physics updates (for instance we’re doing 20 physics updates a second whereas rendering 60 frames per second), then objects will seem to maneuver at a decrease framerate than the sport is working.
The sort of sync challenge might be mitigated with interpolation (averaging movement over earlier physics updates) or extrapolation (rendering the article at a predicted place primarily based on its final place and present velocity), however this has a better efficiency value. There are additionally some negative effects – for interpolation, our rendered objects could also be proven at a barely older place than their precise present place, and for extrapolation, the expected place would possibly overshoot the precise place that the article results in.
A possible compromise is to carry out a physics replace for every body, but additionally carry out further physics updates between frames if the framerate is low (so for instance, setting a minimal physics fee of 60 updates per second, however permitting physics to replace extra usually then that if the sport is working at a better framerate). Relying on the physics engine used, such a inconsistent replace fee could trigger inconsistent or unrealistic habits.
