Search Unity

Third Party Mirror: Sync gameObject movement

Discussion in 'Multiplayer' started by NamelessGames_, Apr 14, 2020.

  1. NamelessGames_

    NamelessGames_

    Joined:
    Jun 4, 2019
    Posts:
    43
    Hi guys.
    I've a GameObject that spawns other GameObjects that should move in map.
    I've given Client Authority on these GameObject to player who owns them, but when it moves them in his istance, the other players don't see them move.

    This is the code

    Code (csharp):
    1. public class Mover : NetworkBehaviour
    2. {
    3.     NavMeshAgent _navmesh;
    4.     public CameraMovement Owner;
    5.  
    6.     private void Awake() {
    7.         _navmesh = GetComponent<NavMeshAgent>();
    8.     }
    9.  
    10.     private void Start() {
    11.     }
    12.  
    13.     // Update is called once per frame
    14.     void Update()
    15.     {
    16.         //Debug.Log(hasAuthority);
    17.         if (!hasAuthority) return;
    18.         if (!Input.GetMouseButtonDown(1)) return;
    19.         RaycastHit hit;
    20.         bool hasHit = Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit);
    21.         if (!hasHit) return;
    22.         Move(hit.point);
    23.     }
    24.  
    25.     private void Move(Vector3 destination) {
    26.         _navmesh.destination = destination;
    27.         _navmesh.speed = 15f;
    28.         _navmesh.isStopped = false;
    29.     }
    30. }
    What's wrong with this?

    This prefab has also these settings:
    NetworkIdentity
    - Server Only: unchecked
    NetworkTransform
    - Client Authority: checked
    SyncInterval: 0
     
    Last edited: Apr 15, 2020
  2. NamelessGames_

    NamelessGames_

    Joined:
    Jun 4, 2019
    Posts:
    43
    Up, I'm desperate.

    I've also tried to send _navmesh.destination via:
    - Command method
    - ClientRPC method
    - Command method that calls ClientRPC method
     
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Add debugging. Figure out if the issue is in Update or Move, and figure out if the issue is the object is moving on the client but not syncing to the server, or not moving anywhere.