
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
- ENet Documentation
- Raylib Documentation
- Game Networking
- Game Networking Patterns
- Game Programming Patterns
- Raylib ENet Example
๐ค Stay Connected Link to heading
- ๐ซ marcius@criogenio.com
- ๐ผ LinkedIn
- ๐ป GitHub