Physics not synchronizing correctly over the network when using Bullet

Posted by Lucas on Game Development See other posts from Game Development or by Lucas
Published on 2012-09-10T02:33:47Z Indexed on 2012/09/10 3:49 UTC
Read the original article Hit count: 257

I'm trying to implement a client/server physics system using Bullet however I'm having problems getting things to sync up.

I've implemented a custom motion state which reads and write the transform from my game objects and it works locally but I've tried two different approaches for networked games:

  1. Dynamic objects on the client that are also on the server (eg not random debris and other unimportant stuff) are made kinematic. This works correctly but the objects don't move very smoothly
  2. Objects are dynamic on both but after each message from the server that the object has moved I set the linear and angular velocity to the values from the server and call btRigidBody::proceedToTransform with the transform on the server. I also call btCollisionObject::activate(true); to force the object to update.

My intent with method 2 was to basically do method 1 but hijacking Bullet to do a poor-man's prediction instead of doing my own to smooth out method 1, but this doesn't seem to work (for reasons that are not 100% clear to me even stepping through Bullet) and the objects sometimes end up in different places.

Am I heading in the right direction? Bullet seems to have it's own interpolation code built-in. Can that help me make method 1 work better? Or is my method 2 code not working because I am accidentally stomping that?

© Game Development or respective owner

Related posts about physics

Related posts about networking