4
\$\begingroup\$

I’m developing a multiplayer network pong game, my first game ever. The current state is, I’ve running the physic engine with the same configurations on the server and the clients. The own paddle movement is predicted and get just confirmed by the authoritative server. Is a difference detected between them, I correct the position at the client by interpolation. The opponent paddle is also interpolated 200ms to 100ms in the past, because the server is broadcasting snapshots every 100ms to each client.

So far it works very well, but now I have to simulate the ball and have a problem to understanding the procedure.

I’ve read Valve’s (and many other) articles about fast-paced multiplayer several times and understood their approach. Maybe I can compare my ball with their bullets, but their advantage is, the bullets are not visible. When I have to display the ball, and see my paddle in the present, the opponent in the past and the server is somewhere between it, how can I synchronize the ball over all instances and ensure, that it got ever hit by the paddle even if the paddle is fast moving? Currently my ball’s position is simply set by a server update, so it can happen, that the ball bounces back, even if the paddle is some pixel away (because of a delayed server position).

Until now I’ve got no synced clock over all instances. I’m sending a client step index with each update to the server. If the server did his job, he sends the snapshot with the last step index of each client back to the clients. Now I’m looking for the stored position at the returned step index and compare them. Do I need a common clock to sync the ball?

EDIT:
I've tried to sync a common clock for the server and all clients with a timestamp. But I think it's better to use an own stepping instead of a timestamp (so I don't need to calculate with the ping and so on - and the timestamp will never be exact). The physics are running 60 times per second and now I use this for keeping them synchronized. Is that a good way?

When the ball gets calculated by each client, the angle after bouncing can differ because of the different position of the paddles (the opponent is 200ms in the past). When the server is sending his ball position, velocity and angle (because he knows the position of each paddle and is authoritative), the ball could be in a very different position because of the different angles after bouncing (because the clients receive the server data after 100ms). How is it possible to interpolate such a huge difference?

I posted this question some days ago at stackoverflow, but got no answer yet. Maybe this is the better place for this question.

\$\endgroup\$
  • 1
    \$\begingroup\$ It's probably easier for somebody to answer this question if you can make it shorter. \$\endgroup\$ – Nicolas Louis Guillemot Jun 23 '14 at 9:58
  • 1
    \$\begingroup\$ This is true, but I would give you as much information as I can. \$\endgroup\$ – Thaars Jun 23 '14 at 11:14
  • \$\begingroup\$ This article appeared after this question: drewblaisdell.com/writing/… \$\endgroup\$ – opyate Mar 2 '17 at 11:53
3
\$\begingroup\$

The ball, by pretty much the law of Pong and physics must either be going towards player one, or player two, not both.

You could use this to switch interpolation priority between the two players. When the ball is heading towards player one then use player one to synchronise your information, as he is the only one that can affect the outcome of if the ball manages to either bounce in the opposite direction or score for player two.

Once the ball starts bouncing in the opposite direction (either because player one succeeded to hit it or player two scored and the next round began) you can then use player two to synchronise your information with. Which ever player has to interact with the ball next, is the player that should report where they and the ball are. This way the lag is only significant against the player who doesn't need the accuracy at that time.

\$\endgroup\$
0
\$\begingroup\$

If your physics are deterministic, could you not broadcast a ball-bounce event, giving a position of the ball and similar statistics, and a step count?

Whilst the ball is in the air the server shouldn't need to keep sending its position, again, if you are using a deterministic model.

\$\endgroup\$
  • \$\begingroup\$ Sounds like an idea, but when the server broadcasts the event and ball data, the clients receive the information delayed and I still have to interpolate a potentially huge difference (depending on the ping). \$\endgroup\$ – Thaars Jun 23 '14 at 12:04
  • \$\begingroup\$ If you are using deterministic physics and not stressing the capabilities of the machine you are running on, you can play catch-up to get the correct ball position. Not sure if that will be possible within whatever framework you're using, but it's what I'd go for. \$\endgroup\$ – Dave Jun 23 '14 at 13:36
  • \$\begingroup\$ Ok, I'll give it a try. I'm using node.js, web sockets and chipmunk physics. Thanks for the hint! \$\endgroup\$ – Thaars Jun 24 '14 at 7:01
  • \$\begingroup\$ just tell one user how the ball was hit by the opposite player, you should NOT synchronize anything in an online game, every once in a while you have to send information to everyone about where stuff are located in the world, but thats that..Lets say im palying an MMORPG, what games do nowadays is to inform the server when, where and how strongly the player hit the enemy. \$\endgroup\$ – Bryan Arbelo - MaG3Stican Jul 23 '14 at 20:59

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.