# Is client-side prediction supposed to cause lag?

I found this general question, but I'd like clarification on a specific point.

Consider this simple scenario:

1. Client A sends input to move at T0.
2. Server receives input at T1.
3. All clients receive the change at T2.

With client-side prediction, client A would start moving at T0, client-side. All other clients receive the change at T2, so to them, client A only started moving at T2.

If I understand correctly, client B will always see client A's past position and not his current position! Is that supposed to happen? How can I sync those clients' world views?

All clients are initialized to the server time when they log in or the game starts, they get updated on this occasionally.

The server uses the "keep alive" ping of the authentication service and lets the clients know what kind of delay they're working with, this delay will change over time and so needs updating occasionally. If you're not using a proper authentication service then the server manages the ping.

All clients know that they are acting "server time + delay" ahead.

Clients then can use this delay and their duplication of server time to properly interpolate forwards proxies from other clients' time and data from the far past so that other clients appear locally in the present on the player's Client, which is actually operating in the near future relative to the Server and that Server is itself in the near past relative to the remote Clients.

tl;dr Sync to server time, keep track of ping, interpolate all proxy clients.

Clear enough? =)

• And: you can't sync both clients completely unless you find a 0ms ping / break the law of physics. You'll always have a some delay and interpolation involved. – Laurent Couvidou May 28 '12 at 21:33
• Thanks for the lengthy explanation! I still don't understand this particular part: 1) Client A input "move right". He starts moving client-side. 2) Input goes to server, then to client B, x ms later. So, client B sees client A move only x ms later. If you put client A and B side by side, A would move instantly on his screen while on B's screen, A would move x ms later. – Legendre May 29 '12 at 12:41
• @Legendre Exactly. Remote players can't start to move instantly, nothing you can do about that. You can see this happen in all games where someone first moves or stops. However, for usual gameplay where people move continuously interpolation works pretty well. The point is that no one plays side by side and therefore no one ever sees all these tricks, all the players care about is if the other people look as if they move normally. In the end because you are developing side by side you are seeing a distorted view of what players see. – Patrick Hughes May 29 '12 at 15:11

A better, and more direct, answer would be: They don't ever sync. When placed side-by-side, Client A will always move first, before client B sees him move.

"Tricks" are then used to resolve this difference. E.g. If one player shoots at another, resolve the shots based on what the shooting player saw, by checking for past positions on the server (Counterstrike etc).

Or, once client A starts moving on client B's machine, it is forward extrapolated in time, to show an "approximation" of where the player will be. New commands are still lagged though. (Tribes etc)