Course contentsShow
← Unity Game Development
Lesson 777 of 82812. Multiplayer and DeploymentFree lesson

Entity Interpolation for Smooth Network Motion

Buffer incoming network updates to render other players' movements with smooth visual transitions rather than jittery, frame-by-frame position snapping.

In this lesson, you will learn how to smooth out remote player movement by decoupling the visual representation from raw network data packets.

The Problem: Network Jitter

When receiving state updates from a server, packets often arrive at irregular intervals due to network jitter. If you move a player object directly to each new position as it arrives, the movement will appear choppy or "teleporty" because the time between updates fluctuates.

The Solution: The Interpolation Buffer

Instead of applying updates instantly, we store them in a buffer and render the entity slightly behind real-time. By maintaining a small delay (typically 50–100ms), we can calculate a smooth path between the previous known state and the current state. We use Vector3.Lerp (Linear Interpolation) to transition the object's transform smoothly between these points over the time window.

Implementation Logic

Imagine we have a buffer containing two snapshots: Snapshot A (old) and Snapshot B (new). We calculate a t value based on the current time relative to the timestamps of these snapshots:

// Logic inside Update()
float interpolationTime = Time.time - interpolationDelay;

// Find the two snapshots that encapsulate our target time
if (interpolationTime > oldestSnapshot.timestamp && interpolationTime < newestSnapshot.timestamp)
{
    float t = (interpolationTime - oldestSnapshot.timestamp) / 
              (newestSnapshot.timestamp - oldestSnapshot.timestamp);
              
    // Smoothly transition visual position
    transform.position = Vector3.Lerp(oldestSnapshot.pos, newestSnapshot.pos, t);
}

By rendering the character at a position calculated from the past, we ensure that as long as we have at least two snapshots in our buffer, the movement remains fluid. Even if the next network packet is delayed by a few milliseconds, the interpolation engine continues to calculate the frame-by-frame movement between the last two known points without stopping or snapping. This gives the illusion of constant, buttery-smooth movement despite the unstable nature of the underlying data stream.

Key Takeaway: Entity interpolation trades a tiny amount of latency for visual fluidity by rendering remote entities slightly in the past, allowing them to glide smoothly between discrete network updates.