Пример #1
0
        //===========================================================================================
        /**
        *  @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 root motion + warping to the animated character transform
        *  
        *  @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)
        {
            Vector3 moveDelta = a_rootDelta + a_warp;
            Quaternion rotDelta = a_rootRotDelta * a_warpRot;

            if (ApplyMovementToController && m_charController != null)
            {
                m_charController.MoveAndRotate(moveDelta, rotDelta);
                //If KCC we need to set the position of the model as well???
            }
            else
            {
                //Apply the root motion directly to the character model but not the controller
                m_rootTransform.SetPositionAndRotation(m_rootTransform.position + moveDelta,
                    m_rootTransform.rotation * rotDelta);
            }

            m_decoupler.UpdatePhase1(a_deltaTime);
        }