1
\$\begingroup\$

I wrote Pong in multiplayer. The clients all run their own game, but I have an authoritative server which enforces its ball position onto the clients.

The game is in sync and playable, however, there is some stuttering on the client side even with a fast connection. I've read that clients could be configured in a way that shows a smooth experience to the player, while in fact the connection may be lagging.

I was thinking about not directly correcting the ball position when a server position update comes in, but to increase or decrease the ball's velocity based on the difference. I didn't manage to get this working properly yet.

Am I thinking in the right direction? How would I make a calculation that shows a smooth experience to the players, while keeping the game in sync?

\$\endgroup\$
  • \$\begingroup\$ Are you using TCP or UDP? \$\endgroup\$ – Philipp Jan 12 '17 at 10:35
1
\$\begingroup\$

Yoh have 2 method, a very simple one and a more complex

The first is to make the ball have a velocity, send that to the client, and use it to interpolate between server updates. This is the easier, and foe a pong game, it should be sufficient.

The second is way more complex and is used by multiple big companies, like Valve. You pretty much send an update from the server, wait for the next one and when it arrives, you start to interpolate between the 2 states. When the next update comes in you take the current state of the object and try to interpolate between it and the update from the server.

A very obvious drawback to this is that the client will always be 20-30 or even 10 ms behind the server, so you need to imllement a backward comouting algorithm for collision.

\$\endgroup\$
  • \$\begingroup\$ Thank you for your answer. In my game, the ball also accelerates. Basically, the clients know the velocity of the ball based on the time. This is why I am only sending the ball position and the time to the clients, so they can calculate the velocity based on the acceleration from there. But there is always some difference between the clients and the server. It might be because of ping. \$\endgroup\$ – Z0q Sep 28 '16 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.