Search Unity

Third Party Mirror not syncing without Network Transform?

Discussion in 'Multiplayer' started by reachout, Apr 22, 2021.

  1. reachout

    reachout

    Joined:
    Jan 15, 2021
    Posts:
    10
    I want to switch to server authoritative syncing and I followed a tutorial with the [Command]/[ClientRpc] way of doing things, but as soon as I turn off Network Transform, rather than everything continuing to work as in the tutorial, my player and the game world objects stop syncing to the client or server. As far as I can tell I've done everything that the tutorial has done except my Move code is a bit longer. Here is my code, hopefully I'm doing something basic wrong.

    Code (cs):
    1.  
    2. using Mirror;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using UnityEngine;
    6.  
    7. public class Player : NetworkBehaviour
    8. {
    9.    public GameObject CameraMountPoint;
    10.    Transform cameraTransform;
    11.    public Rigidbody rbody;
    12.    
    13.    Vector3 realPosition;
    14.    Quaternion totalRotation;
    15.    
    16.    float InputX;
    17.    float InputY;
    18.    
    19.     void Start()
    20.     {
    21.        CmdSetSpawnPoint(); //also spawns
    22.        
    23.        //set camera
    24.        if (isLocalPlayer){
    25.            //Find main camera which is part of the scene instead of the prefab
    26.            cameraTransform = GameObject.Find("Camera").transform;
    27.            //Make the camera a child of the mount point
    28.            cameraTransform.parent = CameraMountPoint.transform;
    29.            //Set position/rotation same as the mount point
    30.            cameraTransform.position = CameraMountPoint.transform.position;
    31.            cameraTransform.rotation = CameraMountPoint.transform.rotation;
    32.        }
    33.     }
    34.    
    35.    public override void OnStopClient () {
    36.        //removes camera form player object before player obj is destroyed
    37.        if (isLocalPlayer){
    38.            cameraTransform.parent = null;
    39.        }
    40.    }
    41.    
    42.    [Command]
    43.    void CmdSetSpawnPoint(){
    44.        RpcSetSpawnPoint();
    45.    }
    46.    
    47.    [ClientRpc]
    48.    void RpcSetSpawnPoint(){
    49.        //gets spawnpoint, moves player there
    50.        GameObject[] spawnpointsArray = GameObject.FindGameObjectsWithTag("SpawnPoint");
    51.        int rand = Random.Range(0, spawnpointsArray.Length);
    52.        GameObject spawnpoint = spawnpointsArray[rand];
    53.         transform.position = spawnpoint.transform.position;
    54.    }
    55.  
    56.     void Update()
    57.     {
    58.        if (isLocalPlayer){
    59.            InputY = Input.GetAxisRaw("Vertical");
    60.            InputX = Input.GetAxisRaw("Horizontal");
    61.            CmdMove();
    62.        }
    63.     }
    64.    
    65.    [Command]
    66.    void CmdMove(){
    67.        RpcMove();
    68.    }
    69.        
    70.    [ClientRpc]
    71.    void RpcMove(){
    72.            float movementY = InputY*4f;
    73.            float movementX = InputX*2.5f;
    74.            
    75.            //AddForce to move forward
    76.            float moveSpeed = 60*Time.deltaTime;
    77.            Vector3 accel = movementY*transform.forward*moveSpeed;
    78.            rbody.AddForce(accel, ForceMode.Impulse);
    79.            realPosition = rbody.position;
    80.            
    81.            float rotateSpeed = 60*Time.deltaTime;
    82.            //Rotate left/right
    83.            Quaternion deltaRotation = Quaternion.Euler(transform.rotation.x, movementX*rotateSpeed, transform.rotation.z);
    84.            totalRotation = rbody.rotation * deltaRotation;
    85.            rbody.MoveRotation(totalRotation);
    86.    }
    87. }
     
  2. reachout

    reachout

    Joined:
    Jan 15, 2021
    Posts:
    10
    So, in case anyone has this in future. I wasn't passing the Input values into the CmdMove and RpcMove functions. I need to pass them in as parameters or else the server and other clients won't recieve the Inputs from the client who moves.
     
    vercus and BenniKo like this.