Rigidbody Collision Synchronisation

Options
Hi,

I've developed a multiplayer motorcycle racing game using PUN:

http://store.steampowered.com/app/668170/Incline

It works very well however, there is an issue with collisions between clients...

My implementation is thus: Send position and rotation across the network, interpolate between them using 100 ms back-time, collisions are handled on the client.

The problem arises when players try to overtake someone. The rigidbodies are roughly 0.5 seconds behind where they appears on the owner's screen due to lag. Somebody may overtake somebody cleanly, but on the opponents screen, they get mowed down from behind.

What I'd like to know is: Is there a way to remedy this using PUN? Or do I need to look into another solution like TrueSync?

If I do have to use TrueSync, how can I integrate it with Unity's wheel colliders? I rely heavily on wheel colliders for my game's physics simulation.

Thank you.

Comments

  • Hi @HomewreckersStudio,

    if you have implemented a OnPhotonSerializeView function for synchronizing the motorcycles yourself, you can add some lag compensation to it. Therefore the sender has to send the rigidbody's velocity additionally. The receiver needs to apply the lag compensation to the received position of the remote motorcycle. To get the time between the moment the message has been sent and the current time, you can use the PhotonMessageInfo, which is the second parameter of the OnPhotonSerializeView function.

    float lag = Mathf.Abs((float)(PhotonNetwork.time - info.timestamp));

    Having this you can add the also received velocity value by doing the following:

    position += (velocity * lag);

    TrueSync is of course another option you have, which would require some additional work.