Multiplayer and box2d

Hi, I've come up with a problem.

In the server, I need to set the positions of players when I get their positions from the clients, which is fine, but if the object has a joint connected to it and I use setTranslation(Vec2 position, float angle), the game freezes. I could destroy and recreate the body every time the server gets the player's position from the client, but this seems like a waste of CPU and might cause other bugs as well.

Is there a better way?

Thanks,
r_bewick
Actually, the engine only crashes if lots of moving objects are spawned ontop of eachother. setTranslation doesn't crash.
Try with the new 2.1.2.2 version, let me know if that still crashes.

In general, networking with physics engines is tough, and the following approaches are common:

  • All things that effect the engine occur with synchronized messages, which synchronize on the frame number. This requires accommodating for network lag
  • Due to machine differences and other errors, objects still need to be synced, so this is done in two ways
    • Partial sync - sync the (projected) linear velocity and angular velocity. Should be some logic in there to watch for collisions during the message transport
    • Full sync - sync everything

Original thread: https://box2d.org/forum/viewtopic.php?t=8048