alt

Interpolation for remote players is a smoothing technique that makes movement of other players (not yourself) look fluid on your screen โ€” even if their updates come in at a lower rate (e.g. 20 Hz) or irregularly due to network jitter.

๐ŸŽฎ Why you need it Link to heading

Without interpolation: Link to heading

  • Remote players would teleport between positions.
  • Every new packet would cause a visual snap.
  • Movement would look laggy or jittery.

With interpolation: Link to heading

  • You buffer past positions, then smoothly animate between them.
  • Movement appears fluid, even over lossy networks.

๐Ÿง  How it works (conceptually) Link to heading

Client stores a short history of snapshots from the server (e.g. last 100โ€“200ms).

Every frame, it finds two snapshots: A and B โ€” before and after the current render time.

It uses linear interpolation to calculate where the player should appear.


Vector2 Interpolate(Vector2 a, Vector2 b, float t) {
      return a * (1.0f - t) + b * t;
  }

a = position at snapshot A
b = position at snapshot B
t = how far between A and B you are (0.0โ€“1.0)

๐Ÿงญ Timeline diagram Link to heading

|-----|-----|-----|-----|-----| <== snapshots from server (e.g. every 50ms)
       ^           ^
    snapshot A   snapshot B
        ^
  interpolation point (render frame at t = 0.5)

๐Ÿ’ก Key trick: Interpolate in the past Link to heading

You render 100โ€“200ms behind real time so you always have two snapshots to interpolate between. This avoids having to extrapolate and guess positions.

โœ… Result Link to heading

  • Movement is buttery smooth.
  • No snapping or jitter.

Combined with client prediction for local players, gives a very polished feel.

โœ… Interpolation for remote players is now added! Link to heading

The client now: Link to heading

  • Buffers incoming snapshots with timestamps.
  • Renders 100ms behind real-time using Lerp().
  • Outputs the interpolated position each frame.

You can tweak INTERPOLATION_DELAY_MS or add velocity interpolation for even smoother motion. Let me know if you want to visualize this or integrate it into a 2D rendering engine like SDL!

I think this is a good stopping point for now. Maybe in the future I can write more about client-side prediction, lag compensation, or other multiplayer techniques.

๐Ÿ“š References Link to heading

๐Ÿค Stay Connected Link to heading