Skip to main content
1 of 2
Philipp
  • 123k
  • 28
  • 264
  • 344

Combining a physics engine that uses a fixed time-step with a variable-timed rendering loop can lead to very choppy movement. Sometimes you have two physics frames between two renders, sometimes none at all and you render the same thing twice. This can lead to choppy movement and scrolling.

The solution to that is to pass not just the current but also the last game-state to the rendering engine and a delta-time variable that states how many milliseconds the current game-state is in the past. That allows the rendering engine to either interpolate or extrapolate object positions accordingly, which results in much smoother movement.

For example:

  • Last tick: object was at horizontal position 3.0
  • Current tick: object is at 5.0
  • Time information: We are 30% between current tick and the next tick

When the rendering engine uses extrapolation, it would calculate that the object is moving with a velocity of 2.0 units per tick, so it now draws it at 5.6 units.

When the rendering engine uses interpolation, then it will linearly interpolate between the last and the current tick and place the object at 3.6 units.

Philipp
  • 123k
  • 28
  • 264
  • 344