I am creating a multiplayer game, and it seems the physics play out slightly different in both of the clients. I have verified the following:
The world is setup as follows (with GRAVITY = 0):
The sim step happens every frame (FRAME_RATE = 30):
I have verified my contact listener is not modifying any of the objects on contact. If anybody could help that would be greatly appreciated! Thank you in advance, and please let me know if you need any additional information.
Although things still get out of sync when this is disabled, here is my top down friction code for anybody who is interested, feel free to use it if you like.
- The vector received by all clients is the same as the one played out on the active player. Example: Player 1 fires an object using certain vector. The exact same x and y values of the vector are used in it's local simulation, as the ones received by the other connected clients. All clients launch the object using body.SetLinearVelocity(velocityVector). This was verified with junkbytes debug console.
- At first I saw the issue when the clients were on different devices, with different resolutions and CPU. But I was able to reproduce by running multiple instances of the game on my PC.
- Every frame I was modifying the bodies velocity (rudimentary top down physics), but disabling this still leads the same issue..
- Simulation seems to play out identical (body locations trace out the same on all clients) as long as there aren't any collisions.
The world is setup as follows (with GRAVITY = 0):
Code: Select all
var gravity:b2Vec2 = new b2Vec2(0, GRAVITY);
PhysiVals.world = new b2World(gravity, true);The sim step happens every frame (FRAME_RATE = 30):
Code: Select all
PhysiVals.world.Step(1 / FRAME_RATE, 6, 4);
PhysiVals.world.ClearForces(); I have verified my contact listener is not modifying any of the objects on contact. If anybody could help that would be greatly appreciated! Thank you in advance, and please let me know if you need any additional information.
Although things still get out of sync when this is disabled, here is my top down friction code for anybody who is interested, feel free to use it if you like.
Code: Select all
private function applyTopDownFriction():void
{
var vel:b2Vec2 = _body.GetLinearVelocity().Copy();
if (vel.Length() > 0.0)
{
if (vel.Length() < 0.1)
{
vel.Set(0, 0);
_body.SetAwake(false);
} else
{
vel.Multiply(_combinedFriction);
}
_body.SetLinearVelocity(vel);
} else {
_body.SetAwake(false);
}
}