Beispiel #1
0
    private void UpdateAxis(Inputs inputs, FreelookRotationType rotationType)
    {
        if (rotationType == FreelookRotationType.RotateOnXYAxis)
        {
            m_freeLookScript.m_XAxis.Value += -inputs.xAxis * m_XRotationSpeed * Time.deltaTime;
        }

        m_freeLookScript.m_YAxis.Value = Mathf.Clamp01(m_freeLookScript.m_YAxis.Value + -inputs.yAxis * m_YRotationSpeed * Time.deltaTime);
    }
Beispiel #2
0
    private void RotateWithInputs(Inputs inputs, FreelookRotationType rotationType)
    {
        // Move the look at target towards the follow target
        if (m_freeLookScript.LookAt.position != m_cameraLookAtTarget.parent.position + m_initialLookAtPositionOffsetRelatifToParent)
        {
            m_freeLookScript.LookAt.position = Vector3.Lerp(m_freeLookScript.LookAt.position, m_cameraLookAtTarget.parent.position + m_initialLookAtPositionOffsetRelatifToParent, m_lookAtTargetMoveSpeed * Time.deltaTime);
        }

        UpdateAxis(inputs, rotationType);
    }
Beispiel #3
0
    private void RotateWithTarget(Inputs inputs, FreelookRotationType rotationType)
    {
        // Use trigonometry to find new look at target position
        Vector3 cameraToTarget = TargetLockedOn.position - m_controledCamera.transform.position;
        Vector3 cameraToInitialLookAtTarget = m_cameraLookAtTarget.parent.position + m_initialLookAtPositionOffsetRelatifToParent - m_controledCamera.transform.position;
        float   distanceCameraToTarget      = cameraToInitialLookAtTarget.magnitude / Mathf.Cos(Vector3.Angle(cameraToTarget, cameraToInitialLookAtTarget) * Mathf.Deg2Rad);
        Vector3 lookAtPosition = m_controledCamera.transform.position + cameraToTarget.normalized * distanceCameraToTarget;

        // Move the look at target towards the target
        m_freeLookScript.LookAt.position = Vector3.Lerp(m_freeLookScript.LookAt.position, lookAtPosition, m_lookAtTargetMoveSpeed * Time.deltaTime);

        UpdateAxis(inputs, rotationType);
    }
Beispiel #4
0
    public void RotateCamera(Inputs inputs, FreelookRotationType rotationType, Transform[] possibleTargets = null)
    {
        // If the camera isn't frozen
        if (!FrozenRotation)
        {
            // Try to find a target
            if (possibleTargets != null)
            {
                FindClosestTargetInSight(possibleTargets);
            }
            else if (TargetLockedOn != null)
            {
                TargetLockedOn = null;

                foreach (IFreeLookCameraControlSubscriber subscriber in m_subscribers)
                {
                    subscriber.NotifyLockOnTargetChanged(null);
                }
            }

            // If a target was found
            if (rotationType == FreelookRotationType.RotateOnYAxis && TargetLockedOn != null)
            {
                RotateWithTarget(inputs, rotationType);
            }
            else
            {
                if (TargetLockedOn != null)
                {
                    TargetLockedOn = null;
                }

                RotateWithInputs(inputs, rotationType);
            }

            if (m_useFade)
            {
                UpdateDistanceFade();
            }
        }
    }