I am developing an
online real-time multiplayer game using Google Play Game Service and Cocos2D-X. The game has two players where each player control their own ball.
The each player sends their
own ball’s velocity and position to the other connected device. In my game, all the physics calculations are done
locally on each devices i.e. ball velocities after physical calculations are calculated locally on each devices.
When fast moving ball collides wth the opponent’s ball, there is
no change in the movement velocity of the opponent’s ball. (According to real world physics, the fast moving ball should be able to push the opponent’s slowly moving ball.)
During my code analysis, I understood that the velocity calculated by the local physics engine are overwritten by the data received from the opponent’s device.
Solution I tried:
To fix the problem, whenever the collision between balls occurs I am creating one of the device as server and other device as client. All the physics calculations occurs on the server device and data is send to the client device.
I have following questions:
- Is the solution tried by me is optimal solution to fix the issue?
What other approaches can be tried to fix such type of issue?
I would appreciate any suggestions/thoughts on this topic. Thank you.