//=========================================================================================== /** * @brief Applies root motion + warping to the character * * @param [Vector3] a_rootPosition - the root position provided by the animator * @param [Quaternion] a_rootRotation - the root rotation provided by the animator * @param [Vector3] a_warp - the positional warping provided by the MxMAnimator (should be added to a_rootPosition) * @param [Quaternion] a_warpRot - the rotation warping provided by the MxMAnimator (should be multiplied with a_rootRotation) * *********************************************************************************************/ public void HandleRootMotion(Vector3 a_rootDelta, Quaternion a_rootRotDelta, Vector3 a_warp, Quaternion a_warpRot, float a_deltaTime) { if (m_rotationOnly) { if (m_charController == null || !m_charController.enabled) { m_rootTransform.rotation *= a_rootRotDelta * a_warpRot; } else { m_charController.Rotate(a_rootRotDelta * a_warpRot); } } else { Vector3 moveDelta = a_rootDelta + a_warp; moveDelta = new Vector3(moveDelta.x * m_axisLock.x, moveDelta.y * m_axisLock.y, moveDelta.z * m_axisLock.z); if (m_charController == null || !m_charController.enabled) { if (EnableGravity) { moveDelta.y = Physics.gravity.y * a_deltaTime * a_deltaTime; } m_rootTransform.Translate(moveDelta, Space.World); m_rootTransform.rotation *= a_rootRotDelta * a_warpRot; } else { if (EnableGravity) { moveDelta.y = (m_charController.Velocity.y + Physics.gravity.y * a_deltaTime) * a_deltaTime; } m_charController.MoveAndRotate(moveDelta, a_rootRotDelta * a_warpRot); } } }
//=========================================================================================== /** * @brief Applies angular error warping to the animated character transform. * * @param [Quaternion] a_warpRot - the rotation warping to apply to the character transform. * *********************************************************************************************/ public void HandleAngularErrorWarping(Quaternion a_warpRot) { if(ApplyMovementToController && m_charController != null) { m_charController.Rotate(transform.rotation * a_warpRot); } else { m_rootTransform.Rotate(a_warpRot.normalized.eulerAngles); } }