Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Zoom to point using oribital camera system and cinemachine 3D

Discussion in 'Cinemachine' started by aaronjostt, Jun 25, 2023.

  1. aaronjostt

    aaronjostt

    Joined:
    Jul 25, 2021
    Posts:
    1
    I have an interesting yet frustrating problem..

    I am creating a "zoom to point" feature in my game, that allows the user to zoom to the mouse cursor in 3D (perspective camera). The cursor should stay on the same xyz position while zooming and moving towards the point. My trouble is achieving the same effect with the freelook/orbital transposer camera in cinemachine. There is a decent chance I'm overthinking it, I nearly went insane yesterday trying to figure this out.

    This can normally be achieved by moving the xyz position of the camera in proportion to the delta between the camera position and the cursor location. With a normal camera this is easily done with something like this
    Code (CSharp):
    1. mainCamera.transform.position = Vector3.MoveTowards(mainCamera.transform.position, Scrolldirection, scrollwheelValue * step);
    Is there a way to shrink/grow the orbital radius of the freelook camera based on a target y position.
    IE: Camera position is at (100,50,-100) and mouse cursor is at (200,0,-200), I zoom on the position half way, so my new camera position should be (150,25,-150) in order to keep my mouse in the same location. Changing the x and z is easy by simply moving the focal point, the problem is the is changing the y by 25 via the orbital radius and height (this will also change the x and z by unknown amounts), I'm not sure how to do that without calculating some reasonably complex math which I rather avoid. Maybe there is simpler way to do this, or Cinemachine method I haven't found?

    I drew a little diagram for y'all

    Appreciate all the help, have a great day!
     

    Attached Files:

  2. JeffG

    JeffG

    Joined:
    Oct 21, 2013
    Posts:
    73
    Use a different virtual camera. When you want to "Zoom to Point", change the priority of the "Zoom to Point Camera". When you are done, put the priority back to 0
     
    Gregoryl likes this.
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,206
    Normally, that is exactly the right answer. With Cinemachine, the paradigm is to have lots of vcams that each do a simple thing, and you combine them with blending. Don't try to make a single camera do everything.

    That said, I think your problem is a little different. Are you just wanting to scale the orbits as a function of the scrollwheel? Don't forget that the orbits are centered on the follow target, not the mouse cursor, so scaling the orbits won't preserve mouse cursor position. Come to think of it, I'm not sure exactly what you want. Can you elaborate?