Esempio n. 1
0
    void UpdateAnimator(Vector3 move)
    {
        // update the animator parameters
        //m_Animator.SetFloat("Forward", m_ForwardAmount, 0.1f, Time.deltaTime);

        //m_ForwardAmount
        //m_TurnAmount
        //m_Crouching

        float normalizedTime = m_Animator.GetCurrentAnimatorStateInfo(0).normalizedTime;

        normalizedTime = normalizedTime - Mathf.FloorToInt(normalizedTime);
        PlayerInput playerInput = new PlayerInput();

        if (m_ForwardAmount >= 1)
        {
            playerInput.velocity        = move.magnitude;
            playerInput.direction       = move.normalized;
            playerInput.angularVelocity = 0.0f;
        }
        else
        {
            playerInput.velocity        = 0.0f;
            playerInput.direction       = Vector3.zero;
            playerInput.angularVelocity = Mathf.Lerp(m_StationaryTurnSpeed, m_MovingTurnSpeed, m_ForwardAmount) * m_TurnAmount;
        }

        playerInput.acceleration = 0.0f;
        playerInput.brake        = 0.0f;
        playerInput.crouch       = m_Crouching;

        string matchedMotionName = motionMatcher.AcquireMatchedMotion(playerInput, this.matchedMotionName, normalizedTime);

        if (this.matchedMotionName != matchedMotionName)
        {
            this.matchedMotionName = matchedMotionName;
            //float bestMotionFrameIndex = motionMatcher.bestMotionFrameIndex;
            float bestMotionFrameIndex = 0;
            float bestMotionTime       = bestMotionFrameIndex / (m_Animator.GetCurrentAnimatorStateInfo(0).length *fps);
            //m_Animator.Play(matchedMotionName, 0, bestMotionTime);
            m_Animator.CrossFade(matchedMotionName, 0.1f);
            Debug.Log("Play matchedMotionName " + matchedMotionName);
        }
    }
    void UpdateAnimator(Vector3 move)
    {
        // update the animator parameters
        //m_Animator.SetFloat("Forward", m_ForwardAmount, 0.1f, Time.deltaTime);
        float normalizedTime = m_Animator.GetCurrentAnimatorStateInfo(0).normalizedTime;

        normalizedTime = normalizedTime - Mathf.FloorToInt(normalizedTime);
        string matchedMotionName = motionMatcher.AcquireMatchedMotion(this.matchedMotionName, move.magnitude, move.normalized, 0f, 0f, normalizedTime, m_Crouching);

        if (this.matchedMotionName != matchedMotionName)
        {
            this.matchedMotionName = matchedMotionName;
            //float bestMotionFrameIndex = motionMatcher.bestMotionFrameIndex;
            float bestMotionFrameIndex = 0;
            float bestMotionTime       = bestMotionFrameIndex / (m_Animator.GetCurrentAnimatorStateInfo(0).length *fps);
            m_Animator.Play(matchedMotionName, 0, bestMotionTime);

            Debug.Log("Play matchedMotionName " + matchedMotionName);
        }
    }