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

Server Reconciliation and Error Correction

Build systems that detect discrepancies between client and server positions, smoothly correcting the local state without causing jarring visual snaps for players.

In this lesson, you will learn how to detect state discrepancies between your client and server and apply a seamless visual correction to prevent jarring "rubber-banding."

When implementing Client-Side Prediction, your local player moves instantly based on input, while the server processes the same input to calculate the "truth." Because of network latency, the server’s calculated position will often differ slightly from your client’s prediction. If you simply snap the player to the server’s position, the movement will feel glitchy.

The Reconciliation Loop

To fix this, the client must keep a local buffer of its recent inputs and the predicted positions resulting from those inputs. When a state update arrives from the server, you compare the server’s timestamped position with your historical record:

  1. Detection: Check if the distance between the server position and the local predicted position exceeds a specific errorThreshold.
  2. Correction: If the error is significant, force the local transform to the server position.
  3. Re-simulation: Since the server update represents the "past," you must re-run all local inputs that occurred after the server's timestamp to "catch up" to the current frame.
void Reconcile(ServerState serverState) {
    // 1. Reset client to authoritative server state
    transform.position = serverState.position;

    // 2. Re-apply all pending inputs that haven't been acknowledged by server
    foreach (var input in pendingInputs) {
        if (input.timestamp > serverState.timestamp) {
            MovePlayer(input); 
        }
    }
}

Smoothing the Correction

Even with re-simulation, tiny differences can cause visual jitter. Instead of hard-setting the position, use Vector3.Lerp or Vector3.MoveTowards over a few frames to interpolate the current visual position toward the corrected coordinate. This hides the error correction from the player, making the movement feel fluid even under sub-optimal network conditions. By maintaining a buffer of inputs and validating them against the server’s heartbeat, you ensure that the game remains responsive while keeping the authoritative server in control.

Key Takeaway: Server reconciliation uses your local input buffer to re-simulate movement from the last known server truth, ensuring a smooth transition back to the correct state without jarring visual snaps.