4
\$\begingroup\$

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.

Issue:


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.)

Reason:

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.

For e.g.
enter image description here

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:

  1. Is the solution tried by me is optimal solution to fix the issue?
  2. What other approaches can be tried to fix such type of issue?

    

I would appreciate any suggestions/thoughts on this topic. Thank you.

\$\endgroup\$

Your Answer

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

Browse other questions tagged or ask your own question.