Client Movement not working

When testing this with 2 instances of the game running I notice that the tank units on the client instance no longer move, where as the host is working as expected. Below is my movement script.

Im using Unity version 2020.2.2

public class UnitMovement : NetworkBehaviour
{
    [SerializeField] private NavMeshAgent agent = null;
    [SerializeField] private Targetter targetter = null;
    [SerializeField] float  chaseRange = 10f;

    #region server

    [ServerCallback]
    private void Update() 
    {
        Targetable target = targetter.GetTarget();

        if(target != null)
        {
            if((target.transform.position - transform.position).sqrMagnitude > chaseRange * chaseRange)
            {
                agent.SetDestination(target.transform.position);
            }
            else if(agent.hasPath)
            {
                agent.ResetPath();
            }
            return;
        }

        if(!agent.hasPath){return;}
        if(agent.remainingDistance > agent.stoppingDistance){return;}

        agent.ResetPath();    
    }

    [Command]
    public void CmdPlayerMove(Vector3 position)
    {
        targetter.ClearTarget();

        if(!NavMesh.SamplePosition(position, out NavMeshHit hit, 1f, NavMesh.AllAreas))return;

        agent.SetDestination(hit.position);
    }

    #endregion

    #region client


    #endregion
}

So this was my mistake. When I was tidying up my tank unit prefab components into a more logical order I must have accidentally removed the Network Transform component. :man_facepalming:

So if anyone else has a similar issue I would recommend you double check to see if you have the correct network components on the prefab.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms