Ejemplo n.º 1
0
        //===========================================================================================
        /**
        *  @brief Update function used to update the controller movement. This update is dependent on 
        *  the Update mode of the Animator component
        *  
        *  @param [float] a_deltaTime - the delta time to use dependent on the update mode.
        *         
        *********************************************************************************************/
        //public void AnimatorDependentUpdate(float a_deltaTime)
        //{
        //    if (m_charController == null)
        //    {
        //        if (EnableGravity)
        //        {
        //            m_moveDelta.y = Physics.gravity.y * a_deltaTime * a_deltaTime;
        //        }

        //        m_rootTransform.Translate(m_moveDelta, Space.World);
        //    }
        //    else
        //    {
        //        //Apply gravity
        //        if (m_charController.enabled && EnableGravity && !m_charController.IsGrounded)
        //        {
        //            m_moveDelta.y = (m_charController.Velocity.y +
        //                Physics.gravity.y * a_deltaTime) * a_deltaTime;
        //        }

        //        //Apply motion to either the controller or the transform
        //        if (m_charController.enabled)
        //        {
        //            m_charController.Move(m_moveDelta);
        //        }
        //        else
        //        {
        //            m_rootTransform.Translate(m_moveDelta, Space.World);
        //        }
        //    }
        //}

        //===========================================================================================
        /**
        *  @brief Sets the position of the character. 
        *  
        *  @param [Vector3] a_position - the new position for the character
        *         
        *********************************************************************************************/
        public void SetPosition(Vector3 a_position)
        {
            if (m_charController.enabled)
            {
                m_charController.Move(a_position - m_rootTransform.position);
            }
            else
            {
                m_rootTransform.position = a_position;
            }
        }
Ejemplo n.º 2
0
        public void UpdateMovementLogic(float a_deltaTime)
        {
            //For this example controller we just extract the motion at the start of the trajectory. 
            //Here I take the first 0.3s of the trajectory
            var motion = m_trajectoryGenerator.ExtractMotion(0.3f);

            Quaternion rotDelta = Quaternion.Inverse(transform.rotation) * Quaternion.AngleAxis(motion.angleDelta, Vector3.up);

            motion.angleDelta = rotDelta.eulerAngles.y;

            //To get the average motion of that 0.3s trajectory per Time.deltaTime we multiply by (Time.deltaTime / 0.3f)
            motion.moveDelta *= (a_deltaTime / 0.3f);
            motion.angleDelta *= (a_deltaTime / 0.3f);

            //The movement extracted from the trajectory is then blended in based on Root motion blending settings on the MxMAnimationDecoupler
            //You only need to do this if you want root motion blending
            motion = m_animDecoupler.CalculateRootMotionBlending(motion.moveDelta, motion.angleDelta, m_trajectoryGenerator.HasMovementInput());

            //Now we apply gravity on top of the root motion blended movement delta. This can be done manually or use built in functionality
            if (!m_charController.IsGrounded)
                motion.moveDelta.y = m_animDecoupler.CalculateGravityMoveDelta(a_deltaTime);

            //Now that we have the final move delta we can apply it to our generic controller wrapper
            m_charController.Move(motion.moveDelta);

            //For this particular movement control I've decided that the rotation of the capsule will always be the same as the model rotation
            //rotation is not particularly important for the controller itself so its relatively trivial. Best to keep it in line with what
            //the player is seeing.
            //m_charController.Rotate(Quaternion.AngleAxis(motion.angleDelta, Vector3.up));

            //transform.rotation = m_trajectoryGenerator.transform.rotation;
        }