Using Photon with Unity's Physics

Options
Hello all,

I'm developing a competitive, real-time multiplayer, 2D physics game, but I can't seem to wrap my head around how I can update all the clients at exactly the same (real) time. This is absolutely necessary if I want Unity's physics simulation to produce the same outcome on all the clients.

It seems that running physics only on the master is probably a clean method; however, this would add a massive bias to the competitive game play, as the other players' inputs would arrive at the master with a slight delay. Not to mention, the simulation outcomes would also propagate to the other clients with a delay. From my experiments, it seems that OnPhotonSerializeView and RPC synchronizations do not execute at the same (real) time for all the clients.

The closest I've gotten to synchronizing game logic is when I kept track of PhotonNetwork.time and the room start time and allowed updates every "x" seconds, for all the clients. However, the slight differences when each client calls its FixedUpdate() method results in a continuous deviation from each other.

I feel like there are too many moving parts that I can't control. It seems that this problem would be easier to solve if I didn't rely so heavily on Unity, but I just don't have the time right now to implement my own game engine.

Would anyone be kind enough to share some input on this, or possibly lead me in the right direction?

--- Thanks for the help.

Comments

  • Tobias
    Options
    Physics in networked games are really hard to get right. Even more so (obviously) in competitive games, where everything has to be correct, or people will complain.

    This topic has been discussed various times. The summary is: We don't have a "out of the box" solution.

    A lockstep mechanism might be best for your game. However, Unity's physics are not deterministic. Maybe 2d is "close enough" for this.

    Sorry. I don't have much input for this, aside from that very vague info.
  • Thanks Tobias. Any input is better than none.

    I understand what you are saying, and I actually didn't know Unity's physics are non-deterministic. I will need to look into this further. I will report back here if I stumble upon a "close enough" solution.

    Thanks again for your help.
  • Tobias
    Options
    Competitive games are tricky, as everyone who's losing will doubt the results and look extra carefully.
    For shooters, there are some techniques to roll-back a few frames to check hits precisely. But that's very niche and I doubt this can be applied here. For physics, I don't know good solutions.

    This page has really good, low level networking input which might help:
    http://gafferongames.com/

    Let us know when you get an acceptable solution.