I connect the clients with UDP (its a peer to peer connection on a multicast network) and the clients are sending their positions in every frame (in WP7 it means the default 30 FPS) to each other. This game is kinda a pong game, and my problem is the next: whenever the opponent hits the ball the angle will not be the same on both mobiles. I think its because the latency (1 pixel difference can cause a different angle). So my question is: how can I sync the hitting event?

  • 1
    \$\begingroup\$ The client being hit should tell the other client what the angle was, the other client shouldn't also calculate it. Or you should have a central server both clients are connected to that calculates it. Or you should have both clients running an enforced identical simulation by having a controlled latency and queue of user inputs. \$\endgroup\$
    – Eric B
    Nov 27 '12 at 16:02

In a multiplayer game, every gameplay-relevant decision should be made by only one system. When multiple systems make a decision, like in your case the trajectory of the ball, and they disagree due to timing issues, the game gets out of sync.

When each client calculates the angle only after its own collisions and sends the new trajectory of the ball to the other, you will get the best results.

But note that this allows the players to cheat. They could manipulate their client to always tell the other client that they hit, and that the ball is now flying in an impossible to catch trajectory. The only way to fix that, is to introduce a neutral referee in form of a central server which receives the users input, calculates all game mechanics, and sends the results to the clients.

By the way: You could safe a lot of bandwidth when you would send the client positions only when they have actually changed, and not on every single frame.

  • \$\begingroup\$ It’s probably the hardest to implement, but an article about network gaming mentioned that you can let both players calculate (to avoid latency at the hitting situation), but then backtrack possible differences so that the ball is at the master position again (in your case the player who hits the ball). \$\endgroup\$ Dec 2 '12 at 19:00

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.