5
\$\begingroup\$

In my online game, I am using client prediction and client interpolation to give the illusion of responsiveness over a networked connection.

The client prediction applies inputs that haven't yet been acknowledged by the server to incoming server states. When the input is acknowledged, the client's entity will already be in the final position.

The client interpolation works by buffering world snapshots and rendering the entities 100 ms in the past. While new snapshots arrive within the next 100 ms, there will always be valid data to interpolate between.

My problem is that the responsiveness gained from client prediction is lost due to client interpolation. The client's local inputs are applied to incoming server states. However, those incoming states aren't actually rendered on the client until 100 ms later, due to the client interpolation. The result is that there is always a 100 ms lag between pressing a key and rendering the change to the screen.

How can I get the best of both worlds, rendering entities in the past, but rendering the client's inputs instantly?

\$\endgroup\$
3
  • 2
    \$\begingroup\$ Just don't do client interpolation on the clients controlled entity? \$\endgroup\$
    – Tili
    Feb 8, 2012 at 16:47
  • 1
    \$\begingroup\$ @Tili Then how can I render the client controlled entity alongside the interpolated ones? \$\endgroup\$
    – Kai
    Feb 8, 2012 at 16:52
  • 2
    \$\begingroup\$ Apply the player input directly on the player entity. The server will then have to okay all the input you did afterward. You only need to interpolate the player entity in case of a correction. \$\endgroup\$
    – Tili
    Feb 9, 2012 at 8:37

1 Answer 1

9
\$\begingroup\$

The problem was a misunderstanding about what client interpolation is for. Only entities that aren't controlled by the player should be interpolated. Player controlled entities always update themselves using the freshest data available from the server, since we want to simulate them as close to real-time as possible.

That also makes clear what client prediction does. If player controlled entities only use the latest data, then how can they be rendered smoothly? Well, since we control that player, we can extrapolate what its next position will be, most of the time with perfect results. Then just render positions between the server-received position and the predicted position.

However, there is still the issue of making the interpolated entities mingle with the player controlled entities during its update step. I solved this by temporarily placing the player controlled entity into the snapshot that is currently being rendered to the screen (from 100 ms ago). The inputs are applied in the context of that snapshot, so the player looks like it's interacting with the interpolated entities. After the simulation is done, the player is removed from the old snapshot.

With all of that in place, it's looking good!

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .