Пример #1
0
        //===========================================================================================
        /**
        *  @brief This is the core function of a motion matching controller. It is responsible for 
        *  updating the trajectory prediction for movement. This movement model can differ between 
        *  controllers but this controller takes a deceivingly simplistic approach. 
        *  
        *  The predicted trajectory output from this function is in evenly spaced points and it is not
        *  necessarily the trajectory passed to the MxMAnimator. Rather, the high resolution trajectory
        *  calculated here will be sampled using the ExtractMotion function before passing data to the
        *  MxMAnimator.
        *         
        *********************************************************************************************/
        protected override void UpdatePrediction()
        {
            //Desired linear velocity is calculated based on user input
            Vector3 desiredLinearVelocity = CalculateDesiredLinearVelocity();

            //Calculate the desired linear displacement over a single iteration
            Vector3 desiredLinearDisplacement = desiredLinearVelocity / p_sampleRate;

            float desiredOrientation = 0f;
            if (m_trajectoryMode != ETrajectoryMoveMode.Normal)
            {
                if (m_camTransform == null)
                {
                    desiredOrientation = Vector3.SignedAngle(Vector3.forward, StrafeDirection, Vector3.up);
                }
                else
                {
                    //If we are strafing we want to make the desired orienation relative to the camera
                    Vector3 camForward = Vector3.ProjectOnPlane(m_camTransform.forward, Vector3.up);
                    desiredOrientation = Vector3.SignedAngle(Vector3.forward, camForward, Vector3.up);
                }
            }
            else if (desiredLinearDisplacement.sqrMagnitude > 0.0001f)
            {
                desiredOrientation = Mathf.Atan2(desiredLinearDisplacement.x,
                    desiredLinearDisplacement.z) * Mathf.Rad2Deg;
            }
            else
            {
                if (m_resetDirectionOnOnInput)
                {
                    desiredOrientation = transform.rotation.eulerAngles.y;
                }
                else
                {
                    desiredOrientation = m_lastDesiredOrientation;
                }
            }

            m_lastDesiredOrientation = desiredOrientation;

            var trajectoryGenerateJob = new TrajectoryGeneratorJob()
            {
                TrajectoryPositions = p_trajPositions,
                TrajectoryRotations = p_trajFacingAngles,
                NewTrajectoryPositions = m_newTrajPositions,
                DesiredLinearDisplacement = desiredLinearDisplacement,
                DesiredOrientation = desiredOrientation,
                MoveRate = m_posBias * m_posBiasMultiplier * Time.deltaTime,
                TurnRate = m_dirBias * m_dirBiasMultiplier * Time.deltaTime
            };

            p_trajectoryGenerateJobHandle = trajectoryGenerateJob.Schedule();
        }
        //===========================================================================================

        /**
         *  @brief This is the core function of a motion matching controller. It is responsible for
         *  updating the trajectory prediction for movement. This movement model can differ between
         *  controllers but this controller takes a deceivingly simplistic approach.
         *
         *  The predicted trajectory output from this function is in evenly spaced points and it is not
         *  necessarily the trajectory passed to the MxMAnimator. Rather, the high resolution trajectory
         *  calculated here will be sampled using the ExtractMotion function before passing data to the
         *  MxMAnimator.
         *
         *********************************************************************************************/
        protected override void UpdatePrediction()
        {
            //Desired linear velocity is calculated based on user input
            Vector3 desiredLinearVelocity = CalculateDesiredLinearVelocity();

            //Calculate the desired linear displacement over a single iteration
            Vector3 desiredLinearDisplacement = desiredLinearVelocity / p_sampleRate;

            float desiredOrientation = 0f;

            if (m_trajectoryMode != ETrajectoryMoveMode.Normal || (!m_hasInputThisFrame && m_faceDirectionOnIdle))
            {
                desiredOrientation = Vector3.SignedAngle(Vector3.forward, StrafeDirection, Vector3.up);
            }
            else if (desiredLinearDisplacement.sqrMagnitude > 0.0001f)
            {
                desiredOrientation = Mathf.Atan2(desiredLinearDisplacement.x,
                                                 desiredLinearDisplacement.z) * Mathf.Rad2Deg;
            }
            else
            {
                desiredOrientation = transform.rotation.eulerAngles.y;
            }

            var trajectoryGenerateJob = new TrajectoryGeneratorJob()
            {
                TrajectoryPositions       = p_trajPositions,
                TrajectoryRotations       = p_trajFacingAngles,
                NewTrajectoryPositions    = m_newTrajPositions,
                DesiredLinearDisplacement = desiredLinearDisplacement,
                DesiredOrientation        = desiredOrientation,
                MoveRate = m_moveResponsiveness * Time.deltaTime,
                TurnRate = m_turnResponsiveness * Time.deltaTime
            };

            p_trajectoryGenerateJobHandle = trajectoryGenerateJob.Schedule();
        }