0
votes

I am creating iOS(iPhone) soccer style game (using cocos2d and box2D) with two players playing realtime and a ball. I am struggling with the synchronisation for a lot of time and just can't get it smooth enough.

Okey so I decided to go with client/server model - One is selected as host(server) and the other is the client. The server and the client have to keep the physics running. And the Client only "mirrors" the physics of the server. The result is that we get smooth game on the server and really non-physic game on the client side -> let's say: after fast hit the ball is calculated to go up but on the next update the server is still thinking that the ball should go down. I use clock sync so I can sync the position and velocity properly on the client side. I know that I can't use client side prediction for physic events like hitting the ball. And I still want to have the physics on the both sides so I can detect collisions properly.

I would really appreciate if anyone shares his experience with this problem.

1

1 Answers

3
votes

Physics in game objects that need to be synchronized over a network is a pretty challenging problem. It's best to avoid it.

Most games tackling this challenge will simulate the game and physics world on the server, and have the clients predict movement. Yes, even for physics objects, typically by simply running the physics simulation (no collisions, or at least no "blocking" collisions) until the server sends an updated state for the game & physics world.

Of course, the faster your connection to the server, the smoother gameplay will be for you. If your device is running the server, you'll always have an edge over the other players unless you introduce artifical lag for the server player and perform the same prediction. That also means running two physic world and updating both on the "server device", once for the actual gameplay state and another time for the predicted client view of the world.