How to synchronize a rigidbody's position that will change owners often

Options
I'm working on a first-person game where players can pickup and throw weapons. Each weapon has a photon view set to takeover, when the weapon is picked up by a player the weapon transfers the ownership of it's photon view to the respective photon player. What I'm trying to figure out is how to synchronize the weapon's position and rotation after a player has thrown it. Not only does the weapon's position need to be synchronized after it is thrown, but when any other player interacts with the weapon's rigidbody after it has been thrown (hits it, pushes it, etc.).

My original thought was that the last player who used the weapon would be in charge of calculating the weapon's physics, the rigidbody would be turned off on all other clients and it's movement would be replicated. But I'm not sure how I would handle the instance where another player tries to interact with the weapon's rigidbody.

This is not critical to the gameplay, so long as it "looks" synchronized and the weapon ends up in the same position on all clients once it has stopped moving, that would be more than enough.

Any help would be great.

Best Answer

  • Rusildo
    Rusildo
    Answer ✓
    Options
    Nobrega said:

    But I'm not sure how I would handle the instance where another player tries to interact with the weapon's rigidbody.

    Use CharacterController (physics component) for Player object. When Player collide with physical object, will be called "OnControllerColliderHit". Inside this method send RPC that add force for Rigidbody.

    See: http://pastebin.com/igtRPfeb

Answers

  • Rusildo
    Rusildo
    Answer ✓
    Options
    Nobrega said:

    But I'm not sure how I would handle the instance where another player tries to interact with the weapon's rigidbody.

    Use CharacterController (physics component) for Player object. When Player collide with physical object, will be called "OnControllerColliderHit". Inside this method send RPC that add force for Rigidbody.

    See: http://pastebin.com/igtRPfeb

  • Nobrega
    Options
    Rusildo said:

    Nobrega said:

    But I'm not sure how I would handle the instance where another player tries to interact with the weapon's rigidbody.

    Use CharacterController (physics component) for Player object. When Player collide with physical object, will be called "OnControllerColliderHit". Inside this method send RPC that add force for Rigidbody.

    See: http://pastebin.com/igtRPfeb

    Thank you for the feedback, I really appreciate you putting together an example! I thought I might be able to do it with an RPC, I'll try this out.