Search Unity

Bug Angular speed doesnt affect my navmesh agent

Discussion in 'Navigation' started by ShavSkelet, May 26, 2022.

  1. ShavSkelet

    ShavSkelet

    Joined:
    Nov 29, 2017
    Posts:
    29
    Im using a navmesh agent with an animator with its root motion handled by script but the navmesh agent rotate so slow, i tryied setting the angular speed to 1000000000 but the agent still rotates slow.

    Any solutions?

    Edit: I think it may be the way im modifying the agent.velocity with the animation. Maybe the velocity on the animation is making the agent to rotate slow?


    Code (CSharp):
    1. private void OnAnimatorMove()
    2.     {
    3.         if (agent != null && animator != null)
    4.         {
    5.             agent.velocity = animator.deltaPosition / Time.deltaTime;
    6.         }
    7.  
    8.     }
    Solution:

    So I was right, the animation velocity was causing the problem, so in case anyone has the same problem, here is my solution to the problem:


    Code (CSharp):
    1. private void OnAnimatorMove()
    2.     {
    3.         if (agent != null && animator != null)
    4.         {
    5.             Quaternion newRotation= Quaternion.LookRotation(agent.velocity.normalized, transform.up);
    6.             Vector3 angles= newRotation.eulerAngles;
    7.             angles.x = 0; angles.z = 0;
    8.             transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(angles), Time.deltaTime * rotationSpeed);
    9.             agent.velocity = animator.deltaPosition / Time.deltaTime;
    10.         }
    11.  
    12.     }
     
    Last edited: May 31, 2022
  2. SOICGeek

    SOICGeek

    Joined:
    Jun 25, 2019
    Posts:
    78
    Does the agent have any kind of physics affecting it? If that's the case, the physics might be overriding the agent's rotation speed. Just a guess.
     
  3. MuaazKhan

    MuaazKhan

    Joined:
    May 18, 2022
    Posts:
    2
    In my case, it was the rotation restrictions