Hi!

Is there a setting to change the focal point of the camera when a camera is set to Rotate Around mode? (Basically change the point the camera rotates around)

If this cannot be achieved through configuration, where in the code should I look to make the change?

    heiser Hi!

    The only way "rotate around point" is implemented at the moment is using 2 fingers on screen. You can find the relevant code, searching for this: "worldPointFingersCenter".

    If you need a special method to rotate around a defined point, I'm gonna have to look into this.

      Here is a method you can put in CameraBase or CameraPerspBase (only testing with perspective camera so far)

          public void RotateAround(Vector2 viewportPoint, float angle)
          {
              Quaternion twistRot = Quaternion.AngleAxis(angle, GetRotateAroundVector());
              Vector2 screenPoint = cam.ViewportToScreenPoint(viewportPoint);
              Vector3 worldPointFingersCenter = ClampInCameraBoundaries(HeightScreenDepth.Convert(screenPoint));
              Vector3 vecFingersCenterToCamera = (finalPosition - worldPointFingersCenter);
              float vecFingersCenterToCameraDistance = vecFingersCenterToCamera.magnitude * 1f;
              vecFingersCenterToCamera = vecFingersCenterToCamera.normalized * vecFingersCenterToCameraDistance;
      
              Vector3 targetPosition = worldPointFingersCenter + vecFingersCenterToCamera;
              Vector3 offsetFromFingerCenter = worldPointFingersCenter - worldPointFingersDelta;
      
              finalPosition = twistRot * (targetPosition - worldPointFingersCenter) + offsetFromFingerCenter;
              finalRotation = twistRot * finalRotation;
      
              currentPitch = NormalizeAngle(finalRotation.eulerAngles.x);
              currentYaw = (finalRotation.eulerAngles.y);
      
              Vector3 newWorldPointCameraCenter = CalculateOffset(finalPosition, finalRotation);
              Vector3 newWorldPointCameraCenterClamped = ClampInCameraBoundaries(newWorldPointCameraCenter);
      
              finalOffset = newWorldPointCameraCenterClamped;
      
              finalPosition = CalculatePosition(finalOffset, finalRotation, finalDistance);
      
              ApplyToCamera();
          }

      Then you can call it from the CustomControlDemo.cs like so:

      if (Input.GetKey(KeyCode.Space))
      {
      cam.RotateAround(new Vector2(0.5f, 0.75f), 30f * Time.deltaTime);
      }

      This will rotate the camera around the viewport point (0.5;0.75) as an example.

        7 days later

        I'll try that out, thank you!

          Write a Reply...