Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

FreeLookCam Zoom to Center of Screen

Discussion in 'Cinemachine' started by sd1515, Aug 12, 2018.

  1. sd1515

    sd1515

    Joined:
    Jan 20, 2018
    Posts:
    5
    I have two Free Look Cameras. One that follows my character, and that zooms when I press the left trigger on my controller.

    My first camera, (normalCam) will always look at and follow my character. For my zoomed in camera (bowCam), is there a way for me to have it zoom in on the center of the screen/direction of the camera, rather than be influenced by player direction?

    I know it has to be something along the lines of...

    bowCamera.GetComponent<CinemachineFreeLook>().m_LookAt = blah;
    bowCamera.GetComponent<CinemachineFreeLook>().m_Follow = blah;

    but I don't know where the grab the values I need to set for blah.

    Thanks!
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,637
    You can get camera Forward by doing vcam.transform.forward. The camera position is given by vcam.transform.position.

    Not sure how you're planning to do the zoom.
    • Do you mean change the FOV? (I doubt it but that's what the word Zoom actually means)
    • Do you mean to grow/shrink the FreeLook orbit radii?
    • Do you mean to transfer the the FreeLook LookAt/Follow targets to some object other than the player? And then... do what? How should the FreeLook behave then?
    Maybe you could describe the desired behaviour a little more precisely, and we could find a solution for you?
     
  3. sd1515

    sd1515

    Joined:
    Jan 20, 2018
    Posts:
    5
    Ah my mistake, I should be clearer: I've changed the FOV for the zoom effect, no problem there.

    And yes, I want to transfer the LookAt/Follow target to something other than the player. I'd like it to be following what I would find as the center/forward of the bowCamera, and then be able to pan the camera left/right/up/down around that target position.

    Would the best route be to change the m_LookAt/m_Follow value? And if so, how can I adjust it to be based on the center of the screen?

    Thanks again for your help!
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,637
    You would have to set the LookAt/Follow targets to some GameObject (perhaps invisible) placed at the location you have in mind. "Center/forward of the bowCamera" defines a ray, not a point, so you would have to choose the point dynamically - possibly based on what intersects a raycast.

    I would create an invisible object to use as a constant target on the second camera, and simply warp it to where you want it to be just before activating the camera. Alternatively, if you have a specific GameObject object that you identify and want to track, just use it as a LookAt and Follow target on the vcam. (vcam.m_LookAt = blah.transform, etc). In that case, just be sure to do it before activating the vcam, or you will get a pop.

    If you want the camera to remain at the same spot when the blend happens, then you will also have to dynamically calculate the orbit radii of the second FreeLook based on the current camera position and the new target location. Again, do that before activating the vcam.