Ejemplo n.º 1
0
    private void LateUpdate()
    {
        currentHorizAngle = CalculateHorizontalAngle();

        float horizAngRad = currentHorizAngle * Mathfs.Deg2Rad;
        float vertAngRad  = VerticalAngle * Mathfs.Deg2Rad;

        Vector3 desiredRelativePosition = new Vector3(Mathfs.Cos(horizAngRad),
                                                      Mathfs.Sin(vertAngRad),
                                                      Mathfs.Sin(horizAngRad)) * Flatness;

        var followTargetPosition     = FollowTarget.position;
        var focalPointToFollowTarget = followTargetPosition - currentFocalPoint;
        var focalPointDelta          = Vector3.Dot(focalPointToFollowTarget, focalPointToFollowTarget);

        float smoothingFactor = Mathfs.Clamp01(focalPointDelta) * trackingSpeed * Time.deltaTime;

        currentFocalPoint         = Vector3.MoveTowards(currentFocalPoint, followTargetPosition, smoothingFactor);
        currentRotatedRelativePos = Vector3.Slerp(currentRotatedRelativePos, desiredRelativePosition, RotateSpeed * Time.deltaTime);

        transform.position = currentFocalPoint + currentRotatedRelativePos;
        transform.rotation = Quaternion.LookRotation(currentFocalPoint - transform.position, Vector3.up);

        // tie FoV to distance
        cam.fieldOfView = Mathf.Atan(Zoomness / Flatness) * Mathf.Rad2Deg * 2.0f;
    }
Ejemplo n.º 2
0
    private (float, float, float) BlendCameras(float a, float b, float t)
    {
        float smoothT   = Mathfs.Smooth01(Mathfs.InverseLerpClamped(a, b, t)) * 2.0f;
        float firstCam  = Mathfs.Clamp01(1 - smoothT);
        float blendCam  = Mathfs.Max(1 - Mathfs.Abs(1 - smoothT), 0);
        float secondCam = Mathfs.Clamp01(smoothT - 1);

        var result = (firstCam, blendCam, secondCam);

        return(result);
    }
Ejemplo n.º 3
0
    public override void Update(GameObject camera)
    {
        Vector3 playerPos          = player.transform.position + focalPointOffset;
        Vector3 focalPointToTarget = playerPos - focalPoint;
        float   focalPointDelta    = Vector3.Dot(playerPos, focalPointToTarget);

        float t = Mathfs.Smooth01(Mathfs.Clamp01(focalPointDelta)) * trackingSpeed * Time.deltaTime;

        focalPoint = Vector3.MoveTowards(focalPoint, playerPos, t);

        var finalPos = focalPoint + positionOffset;

        camera.transform.position = finalPos;
        camera.transform.rotation = Quaternion.LookRotation(playerPos - finalPos, Vector3.up);
    }
 public static Vector4 Clamp01(this Vector4 v) =>
 new Vector4(Mathfs.Clamp01(v.x),
             Mathfs.Clamp01(v.y),
             Mathfs.Clamp01(v.z),
             Mathfs.Clamp01(v.w));
 public static Vector3 Clamp01(this Vector3 v) =>
 new Vector3(Mathfs.Clamp01(v.x),
             Mathfs.Clamp01(v.y),
             Mathfs.Clamp01(v.z));
 public static Vector2 Clamp01(this Vector2 v) =>
 new Vector2(Mathfs.Clamp01(v.x), Mathfs.Clamp01(v.y));
 public static float Clamp01(this float v) => Mathfs.Clamp01(v);