Beispiel #1
0
    void LateUpdate()
    {
        if (logicCamera == null)
        {
            return;
        }
        if (objectToFollow != null)
        {
            cameraInfo.targetVelocity = (objectToFollow.position - oldTargetPosition) / Time.deltaTime;
            oldTargetPosition         = objectToFollow.position;
            cameraInfo.targetPosition = objectToFollow.position;
            cameraInfo.targetRotation = objectToFollow.rotation;
        }
        else
        {
            cameraInfo.targetPosition = new Vector3();
            cameraInfo.targetRotation = new Quaternion();
            cameraInfo.targetVelocity = new Vector3();
        }
        cameraInfo.pivotDistance          = 0;
        cameraInfo.pivotOffset            = 0;
        cameraInfo.pivotRotationIsDefined = false;
        cameraInfo.useSourcePosition      = false;
        cameraInfo.useTargetPosition      = false;

        cameraInfo.fov = currentFov;

        logicCamera.UpdateCamera(ref cameraInfo);

        GetComponent <Camera>().fieldOfView = cameraInfo.fov;
        if (cameraInfo.useSourcePosition)
        {
            var deltaPosition = cameraInfo.targetPosition - cameraInfo.sourcePosition;
            if (deltaPosition.magnitude > 0.01f)
            {
                transform.rotation = Quaternion.LookRotation(deltaPosition);
            }
            else
            {
                transform.rotation = Quaternion.Euler(0, 0, 0);
            }
            transform.position = cameraInfo.sourcePosition;
            ShakeCamera();
        }
        else
        {
            var newPosition = cameraInfo.CameraPosition();
            var newRotation = cameraInfo.PivotRotation();
            transform.position = newPosition;
            transform.rotation = newRotation;
        }
        cameraInfo.cameraSwitched = false;
    }
    public override void UpdateCamera(ref LogicCameraInfo cameraInfo)
    {
        DebugUtilities.Assert(logicCamera != null, "LogicCamera can not be null for player camera");
        if (Time.deltaTime < 0.000001)
        {
            return;
        }

        logicCamera.UpdateCamera(ref cameraInfo);

/*
 *              var headOffset = new Vector3();
 *              const float headRadius = 2.0f;
 *              const float headHeight = 0.8f;
 *              if (cameraInfo.pivotDistance < headRadius)
 *              {
 *                      headOffset.y = ((headRadius - cameraInfo.pivotDistance) / headRadius) * headHeight;
 *              }
 *
 */
    }