Hello all,
I’ve been doing the RPG course for the last couple of days now and I’m at the “First Moment” section. I’m supposed to “Tweak Enemy Patrol” where I suddently realised that the enemies never enter the walk animation. The animation is running, but very slow and the animation isn’t following the movement speed. I’ve attached two screenshots of the Inspector and also the Mover.cs script.
Can any of you brilliant minds help me out?
Thanks!
using RPG.Core; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI; namespace RPG.Movement { public class Mover : MonoBehaviour, IAction { //[SerializeField] Transform target; [SerializeField] float maxSpeed = 6f; NavMeshAgent navMeshAgent; Health health; private void Start() { navMeshAgent = GetComponent<NavMeshAgent>(); health = GetComponent<Health>(); } void Update() { navMeshAgent.enabled = !health.IsDead(); UpdateAnimator(); } public void StartMoveAction(Vector3 destination, float speedFraction) { GetComponent<ActionScheduler>().StartAction(this); MoveTo(destination, speedFraction); } public void MoveTo(Vector3 destination, float speedFraction) { navMeshAgent.destination = destination; navMeshAgent.speed = maxSpeed * Mathf.Clamp01(speedFraction); 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); } }
}