cocos2d-xchipmunk

Cocos2d physics is not the same across all devices


I'm developing a network demo game using cocos2d-x and chipmunk. I have a problem with physics when i ( ApplyImpuse() ) to one sprite in one device and send that Vec2 force to the other device and apply the same impulse to the sprite the simulation is pretty different than what i got in the first device.

I tests it many times with different devices.

Note : I don't use any custom update method i just ApplyImpulse() to the sprite when i touch the screen.

Can anyone describe this issue and propose any solution for it please ?

If i switched to Box2D will this problem be solved??

Thanks.


Solution

  • No. The only way to get a deterministic simulation across many devices is to use (or rewrite) the physics library to use fixed point math, and then deal with all the limitations that brings.

    It is nearly impossible to get deterministic results from floating point numbers from different CPUs, compilers, platforms, or even most minor code changes. For example, a*b + a*c could be simplified by the compiler to a*(b + c), but since floating point numbers have limited precision, the result will likely not be exactly the same.

    Contraption Make started out using vanilla Chipmunk, but eventually rewrote significant portions of it using fixed point: http://www.moddb.com/members/kevryan/blogs/the-butterfly-effect-deterministic-physics-in-the-incredible-machine-and-contraption-maker