Exemple #1
0
    void ApplyControlRotation()
    {
        if (!m_UseControlRotation)
        {
            return;
        }
        if (!_PlayerController)
        {
            return;
        }

        var controlRotation = _PlayerController.GetControlRotationToEuler();
        var targetRotation  = transform.eulerAngles;

        targetRotation.x = m_UseControlRotationPitch ? controlRotation.x : targetRotation.x;
        targetRotation.y = m_UseControlRotationYaw ? controlRotation.y : targetRotation.y;
        targetRotation.z = m_UseControlRotationRoll ? controlRotation.z : targetRotation.z;

        Vector3 newEulerAngle = targetRotation;

        if (m_UseDesiredRotation)
        {
            newEulerAngle.x = Mathf.LerpAngle(
                transform.eulerAngles.x, targetRotation.x,
                m_RotationRate.x * Time.deltaTime);

            newEulerAngle.y = Mathf.LerpAngle(
                transform.eulerAngles.y, targetRotation.y,
                m_RotationRate.y * Time.deltaTime);

            newEulerAngle.z = Mathf.LerpAngle(
                transform.eulerAngles.z, targetRotation.z,
                m_RotationRate.z * Time.deltaTime);
        }


        transform.eulerAngles = newEulerAngle;
    }