[NGO] client movement

I’m starting as a host. The prefab with the player will spawn well, and his management works with a bang. But when I still connect as a client, it also works, but the movement of the client player seems to be blocked, although I output logs and they work, and the object itself remains in place. If you turn off Network Transform on the client, the management on the client starts working, but it does not synchronize accordingly.

Scripts for player prefab:

public class PlayerMovement : NetworkBehaviour
{
    CharacterController characterController;
    public Transform cameraTransform;
  
    float pitch = 0f;
    // Start is called before the first frame update
    public NetworkVariable<Vector3> Position = new NetworkVariable<Vector3>();
    public void Start()
    {
       
        if (!IsLocalPlayer) {
            cameraTransform.GetComponent<AudioListener>().enabled = false;
            cameraTransform.GetComponent<Camera>().enabled = false;
            transform.GetComponent<PlayerMovement>().enabled = false;
          
        }
        else {
characterController = GetComponent<CharacterController>();
Cursor.lockState = CursorLockMode.Locked;
        }
       
    }

    // Update is called once per frame
    void Update()
    {
     
       if (IsLocalPlayer) {
MovePlayer();
Look();
       }
      
    }
    void MovePlayer() {
       
Debug.Log("Двигаем игрока! Горизонталь: " + Input.GetAxis("Horizontal") + "Вертикаль: " + Input.GetAxis("Vertical"));
Vector3 move  = new Vector3(Input.GetAxis("Horizontal"), 0 , Input.GetAxis("Vertical") );
move = Vector3.ClampMagnitude(move, 1f);
move = transform.TransformDirection(move);
characterController.SimpleMove(move * 5f);
    }

    void Look() {
        float mouseX = Input.GetAxis("Mouse X") * 3f;
        transform.Rotate(0,mouseX,0);
        pitch -= Input.GetAxis("Mouse Y") * 3f;
        pitch = Mathf.Clamp(pitch, -45f, 45f);
cameraTransform.localRotation = Quaternion.Euler(pitch,0,0);

    }
1 Like

solved the problem. It turns out that the Client Network Transform script needs to be specified on the player’s prefab, instead of Network Transform

Could you explain more about this “Client Network Transform”? I have the same issue that host can move and is seen by client but client itself cannot move.

where the “player” prefab in MLAPI was enough to add the “Network Transform” component. And the NGO (netcode) uses “Client Network Transform”. As I understand it, this is done so that Network Transform is controlled only by the host, and not by the client

1 Like

The Client Network Transform lets you use a client authoritative approach, but this isn’t suitable for all types of games and has some implications for physics related to object ownership.

To make things work as expected using Network Transform, you need to use ServerRPCs from the client to update NetworkVariables that the Server can then operate on. Back on the client side, you use these NetVars instead of just local ones generated by your inputs so draw and so on.

1 Like