UCC + BD: NavMeshAgentMovement Update Request

Hello.

Currently when an agent is seeking a destination using the NavMeshAgentMovement ability and the agent is aiming they will only move toward where they are aiming. That is to say that NavMeshAgentMovement does not take in consideration whether or not m_UpdateRotation is selected in the behavior action. No matter what, it tries to point the agent toward the velocity of the path.

I'd like to submit a change to the NavMeshAgentMovement that does take in consideration whether the agent is trying to move while aiming or if the BD action has UpdateRotation set to false.


In NavMeshAgentMovement: From This

C#:
if (m_NavMeshAgent.desiredVelocity.sqrMagnitude > 0.01f && m_NavMeshAgent.remainingDistance > 0.01f && m_LastPathPendingFrame + 2 < Time.frameCount) {
                    lookRotation = Quaternion.LookRotation(m_NavMeshAgent.desiredVelocity, m_CharacterLocomotion.Up);
                    // The normalized velocity should be relative to the target rotation.
                    var velocity = Quaternion.Inverse(lookRotation) * m_NavMeshAgent.desiredVelocity;
                    // Only normalize if the magnitude is greater than 1. This will allow the character to walk.
                    if (velocity.sqrMagnitude > 1) {
                        velocity.Normalize();
                    }
                    m_InputVector.x = velocity.x;
                    m_InputVector.y = velocity.z;
                }


To This:

C#:
if (m_NavMeshAgent.desiredVelocity.sqrMagnitude > 0.01f && m_NavMeshAgent.remainingDistance > 0.01f && m_LastPathPendingFrame + 2 < Time.frameCount)
                {
                    var velocity = Vector3.zero;
                    if (m_UpdateRotation)
                    {
                        lookRotation = Quaternion.LookRotation(m_NavMeshAgent.desiredVelocity, m_CharacterLocomotion.Up);
                        // The normalized velocity should be relative to the target rotation.
                        velocity = Quaternion.Inverse(lookRotation) * m_NavMeshAgent.desiredVelocity;
                    }
                    else
                    {
                        Quaternion agentRotation = m_CharacterLocomotion.transform.rotation;
                        velocity = Quaternion.Inverse(agentRotation) * m_NavMeshAgent.desiredVelocity;
                    }

                    // Only normalize if the magnitude is greater than 1. This will allow the character to walk.
                    if (velocity.sqrMagnitude > 1)
                    {
                        velocity.Normalize();
                    }
                    m_InputVector.x = velocity.x;
                    m_InputVector.y = velocity.z;
                }
            }
 
Last edited:
Thanks for bringing this up! I like it - I'll make a similar change. There may even be a way to have it automatically decide if it should update the rotation or not instead of needing the extra bool. I'll take a look into it and have a proper change for the next update.
 
Top