Rickochete sync problem

Options
Hello, I have a bullet instantiated with RPC (AllViaServer), the bullet is Rigidbody (just for collision detection) with frozen constraints and I'm moving it with transform.Translate (bullet.forward * speed).
In OnCollisionEnter method I'm calculating reflected direction based on first contact point and change bullet's facing vector. The problem is that sometimes (rather often) bullets are reflected in different directions on each client, is there any way I can fix this?

Comments

  • Hi @NBGYALTA,

    currently each client calculates the new facing vector for himself and because Unity's physics engine is not deterministic each client calculates different results. What you can do instead is to calculate the new facing vector only on one client (maybe the one who actually instantiated the object) and synchronize this value besides the current position, rotation and velocity of the Rigidbody with the other clients.
  • Shibli
    Options

    Hi @NBGYALTA,

    currently each client calculates the new facing vector for himself and because Unity's physics engine is not deterministic each client calculates different results. What you can do instead is to calculate the new facing vector only on one client (maybe the one who actually instantiated the object) and synchronize this value besides the current position, rotation and velocity of the Rigidbody with the other clients.

    Hi @Christian_Simon ,
    Would that mean the bullet needs to be instantiated by Photon instead of being instantiated with an RPC? Wouldn't that make more messages on the server because you are asking for the position and rotation to be synced after ricocheting and that would require a photonView to be attached to the object.
  • Hi @Shibli,

    Would that mean the bullet needs to be instantiated by Photon instead of being instantiated with an RPC?


    There wouldn't be a difference as far as I would say.

    Wouldn't that make more messages on the server because you are asking for the position and rotation to be synced after ricocheting and that would require a photonView to be attached to the object.


    Yes, you would have to find a solution where for example the owner of the object can inform the other clients about the behaviour of this object. Attaching a PhotonView component seems to be the easiest solution therefore. So you can either work with a custom OnPhotonSerializeView function, one of the existing View scripts (e.g. PhotonTransformView) or with RPCs which get fired when the object actually 'ricochets' on the local client and send the new direction for example.
  • Shibli
    Options
    @Christian_Simon I think we need tutorials to demo the basics of Photon. Are there any ? Could I make some? If I do who should I get them edited or checked by?
  • There are demos available that are coming with the PUN package form the Asset Store. There are also documentation pages available which you can find here. Please note, that we can't provide tutorials, demos or something similar for any existing (and sometimes very specific) scenario.

    Could I make some? If I do who should I get them edited or checked by?


    You can of course make some unofficial tutorials for certain problems or scenarios, but we can't promise to ever take a look at them in order to see, if those solutions are correct, efficient or whatever. Thanks for your effort anyway.