Can't move (again)

I was following the tutorial again after fixing my previous errors, but now I must have broke something because my character can’t move. I didn’t change anything from any of the previous lessons…?

using System.Collections;
using System.Collections.Generic;
using RPG.Combat;
using RPG.Core;
using UnityEngine;
using UnityEngine.AI;

namespace RPG.Movement
{
    
    public class Mover : MonoBehaviour, IAction
    {
        [SerializeField] Transform target;

        NavMeshAgent navMeshAgent;
        private void Start()
        {
            navMeshAgent = GetComponent<NavMeshAgent>();
        }
        void Update()
        {
            UpdateAnimator();
        }
        public void StartMoveAction(Vector3 destination)
        {
            GetComponent<ActionScheduler>().StartAction(this);
            GetComponent<Fighter>().Cancel();
            MoveTo(destination);
        }

        public void MoveTo(Vector3 destination)
        {
            navMeshAgent.destination = destination;
            navMeshAgent.isStopped = false;
        }

        
        public void Cancel()
        {
            navMeshAgent.isStopped = true;
        }
        private void UpdateAnimator()
        {
            Vector3 velocity = navMeshAgent.velocity;
            Vector3 localVelocity = transform.InverseTransformDirection(velocity);
            float speed = localVelocity.z;
            GetComponent<Animator>().SetFloat("forwardSpeed", speed);
        }
    }
}

Aside from the line cancelling the Fighter method, the Mover looks correct.

Are there any errors in the console when you try to move?

Most likely, the issue is in the PlayerController not instructing the player to move. Paste in your PlayerController.cs and we’ll take a look.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RPG.Combat;
using RPG.Movement;


namespace RPG.Control
{
    public class PlayerController : MonoBehaviour
    {
        private void Update()
        {
            if (InteractWithCombat()) return;
            if (InteractWithMovement()) return;
        }

        private bool InteractWithCombat()
        {
            RaycastHit[] hits = Physics.RaycastAll(GetMouseRay());
            foreach (RaycastHit hit in hits)
            {
                CombatTarget target = hit.transform.GetComponent<CombatTarget>();
                if (target = null) continue;

                if (!GetComponent<Fighter>().CanAttack(target.gameObject))
                {
                    continue;
                }

                if (Input.GetMouseButtonDown(0))
                {
                    GetComponent<Fighter>().Attack(target.gameObject);
                }
                return true;
            }
            return false;
        }

        private bool InteractWithMovement()
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            bool hasHit = Physics.Raycast(ray, out hit);
            if (hasHit)
            {
                if (Input.GetMouseButtonDown(0))
                {
                    GetComponent<Mover>().StartMoveAction(hit.point);
                }
                return true;
            }
            return false;
        }

        private static Ray GetMouseRay()
        {
            return Camera.main.ScreenPointToRay(Input.mousePosition);
        }
    }
}

Thanks you are the most helpful person on the forums!

Are there any errors in the console?
Is the NavMeshAgent enabled on the Player?
Can the Player move to attack an enemy?

There are no console errors which is what is puzzling.

Yes it is.

The Player can’t move at all.

Let’s add some Debugs to see if we can figure out what’s going on.

In Mover, let’s modify the following methods:

        public void StartMoveAction(Vector3 destination)
        {
            Debug.Log($"{name} StartMoveAction({destination})");
            GetComponent<ActionScheduler>().StartAction(this);
            // GetComponent<Fighter>().Cancel();
            MoveTo(destination);
        }

        public void MoveTo(Vector3 destination)
        {
            Debug.Log($"{name} MoveTo({destination});");
            navMeshAgent.destination = destination;
            navMeshAgent.isStopped = false;
        }

And in PlayerController.InteractWithMovement:

        private bool InteractWithMovement()
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            bool hasHit = Physics.Raycast(ray, out hit);
            if (hasHit)
            {
                if (Input.GetMouseButtonDown(0))
                {
                    Debug.Log($"{name} PlayerController calling StartMoveAction({hit.point})");
                    GetComponent<Mover>().StartMoveAction(hit.point);
                }
                Debug.Log($"Mouse cursor is over a moveable location");
                return true;
            }
            Debug.Log($"Mouse Cursor is not over a moveable location");
            return false;
        }

Privacy & Terms