To put my problem into some context; I am developing a multiplayer game in which clients can interact with entities in the physics space. I want other clients to be able to see the interactions which other clients make with objects.
I know this is not the best way to achieve multiplayer physics, but this is the way I am currently doing it:
As it currently stands, when a client hits an entity, that client “claims ownership” of that entity, and will (effectively) send the:
- PhysicsLocation, PhysicsRotation, LinearVelocity, & AngularVelocity
… of that entity to the other clients. The other clients then clear all forces from the entity in question, and apply those properties to the entity.
Theoretically, if the entities are setup to have the same Physical properties on all clients and the physical world being identical, performing the above should result in all clients simulating exactly the same outcome - with the entity starting and finishing in the same place… shouldn’t it??
It’s not like the entities are going in VASTLY different locations (e.g. I hit it with a tiny force and it ends up being catapulted across the world for the other clients) but they are none the less ending up in different places for different clients.
Firstly, I know that this is not the best way of handling physics - I could for example have all physics simulated on the server side and then distributing the location/rotation of entities to clients… But I have chosen to do it this way.
I was thinking that maybe I am not getting equal results because:
- The clients are initializing their physics spaces with different random seeds (do these even exist for JME3’s bulletAppState?)
- The clients are simulating the physics at different in-game times?
- It could be that there’s some other force that I need to provide the clients with that I omitted from the list above
Would you kindly be able to shed some light on why the clients are simulating some-what different results from the same inputs, and moreover, suggest how I can go about solving this problem?
I just need the other clients to be able to accurately replicate (deterministically) the same simulation on their side.
~Thanks in anticipation! ~
When I refer to an “entity” I am talking about any Spatial for which I have created a collision shape and added it to the physics space; provided by bulletAppState.