using RPG.Core; using UnityEngine; using UnityEngine.AI; using UnityEngine.InputSystem; namespace RPG.Movement { public class Mover : MonoBehaviour, IAction { [SerializeField] private Transform target; // Cache components for performance private NavMeshAgent navMeshAgent; private Animator animator; private void Awake() { // Get component references once navMeshAgent = GetComponent(); animator = GetComponent(); } void Update() { UpdateAnimator(); } public void StartMoveAction(Vector3 destination) { GetComponent().StartAction(this); 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; animator.SetFloat("forwardSpeed", speed); } } }