public override void Update()
{
m_InputVector = Vector2.zero;
var AimAbility = m_CharacterLocomotion.GetAbility<Items.Aim>();
if (AimAbility != null && AimAbility.IsActive)
{
var lookRotation = Quaternion.LookRotation(m_CharacterLocomotion.LookSource.LookDirection(true), m_CharacterLocomotion.Up);
var forwardRotation = Quaternion.LookRotation(m_Transform.forward, m_CharacterLocomotion.Up);
var moveRotation = Quaternion.LookRotation(m_Transform.forward, m_CharacterLocomotion.Up);
if (m_NavMeshAgent.isOnOffMeshLink)
{
UpdateOffMeshLink();
}
else
{
// When the path is pending the desired velocity isn't correct. Add a small buffer to ensure the path is valid.
if (m_NavMeshAgent.pathPending)
{
m_LastPathPendingFrame = Time.frameCount;
}
// Only move if a path exists.
if (m_NavMeshAgent.desiredVelocity.sqrMagnitude > 0.01f && m_NavMeshAgent.remainingDistance > 0.01f && m_LastPathPendingFrame + 2 < Time.frameCount)
{
moveRotation = 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;
}
}
//var rotation1 = lookRotation * Quaternion.Inverse(m_Transform.rotation);
var rotation2 = lookRotation * Quaternion.Inverse(m_Transform.rotation);
m_DeltaYawRotation = Utility.MathUtility.ClampInnerAngle(rotation2.eulerAngles.y);
//this.m_Transform.rotation = rotation1;
} else
{
var lookRotation = Quaternion.LookRotation(m_Transform.forward, m_CharacterLocomotion.Up);
if (m_NavMeshAgent.isOnOffMeshLink)
{
UpdateOffMeshLink();
}
else
{
// When the path is pending the desired velocity isn't correct. Add a small buffer to ensure the path is valid.
if (m_NavMeshAgent.pathPending)
{
m_LastPathPendingFrame = Time.frameCount;
}
// Only move if a path exists.
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;
}
}
var rotation = lookRotation * Quaternion.Inverse(m_Transform.rotation);
m_DeltaYawRotation = Utility.MathUtility.ClampInnerAngle(rotation.eulerAngles.y);
}
base.Update();
}