Enemies never switch to walk animation *RPG COURSE*

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? :slight_smile:

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);
    }
}

}

Everything looks right here…
If the animation isn’t matching the movement speed, then it’s likely that the speed in the animation blend tree isn’t right. Post up a screenshot of the blend tree and we’ll take a look
image

2 Likes

Hello Brian,

Thank you. You are right. The problem was that the HumanoidWalk motion was at 2.8something… Everything works fine now :slight_smile:

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

Privacy & Terms