Using magnitude

Hi,

I did it a different way, I was wondering if this is good enough, it seems to work.
The character can move in any direction at full speed and all the blend animations work.

Does anyone know if there are any downsides to doing it this way (using Navmesh.velocity and then using the magnitude of the value in a float).

Thanks :slight_smile:

1 Like

There are many paths to the same goal. As long as it works, it should be fine.

1 Like

Nice, thanks Brian :grinning_face_with_smiling_eyes:

I just did it the same way, like this:

public class Mover : MonoBehaviour
{
    private readonly int LOCOMOTION_FORWARD_SPEED = Animator.StringToHash("ForwardSpeed");
//...
    void Start()
    {
        animator = GetComponent<Animator>();
        mainCamera = Camera.main;
        agent = GetComponent<NavMeshAgent>();
    }
//...
    private void UpdateAnimator()
    {
        float currentVelocity = agent.velocity.magnitude;
        animator.SetFloat(LOCOMOTION_FORWARD_SPEED, currentVelocity);
   }
}

Keep in mind that this way you check for overall speed along all axes, not just the forward speed (along the z axis) as in the video

Privacy & Terms