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 writes the transform from my game objects and it works locally but I've tried two different approaches for networked games:
- 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
- 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?
EDIT: Another problem with method 1 I just noticed is that the collision response will be way off for collisions against non-synchronized objects. Kinetic bodies kind of shoot stuff to infinity sometimes since they can't be knocked back.