How to move a character by clicking the mouse using NavMeshAgent.

Options
hot_tigesr
edited January 2023 in Fusion

Hello. I am new to these forums and Fusion. 

I'm trying to move the character to the mouse click. The current character movement is working when Network Input key is received in FixedUpdateNetwork().

I don't know how to use NavMeshAgent here.

I want move click point using moveVector entered below. Please help me out.

public void OnInput(NetworkRunner runner, NetworkInput input)
{
    ...

    Vector3 heading = MainCamera.transform.localRotation * Vector3.forward;
    heading.y = 0;
    heading = heading.normalized;
        
    Vector3 moveVector;
    float vertical, horizontal;

    vertical = Input.GetAxis("Vertical");
    horizontal = Input.GetAxis("Horizontal");
    moveVector = heading * Time.deltaTime * vertical;
    moveVector += Quaternion.Euler(0, 90, 0) * heading * Time.deltaTime * horizontal;
        
    NetworkInputData frameworkInput = new NetworkInputData();
    frameworkInput.MoveVector = moveVector;
     
    input.Set(frameworkInput);
}

public override void FixedUpdateNetwork()
{
    if (GetInput(out NetworkInputData input))
    {
        MoveDirection = input.MoveVector;
        float keyMag = MoveDirection.magnitude;
        NewController.Move(MoveDirection);
        DetermindState(keyMag);
    }
}