Search Unity

  1. Unity 2018.3 is now released.
    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. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Orth. Cam: Something like target group but with fixed camera position possible with Cinemachine?

Discussion in 'Cinemachine' started by Sharlatan, Jan 8, 2019.

  1. Sharlatan

    Sharlatan

    Joined:
    Jul 23, 2013
    Posts:
    78
    Hey everyone!

    Is something like the following easily possible with Cinemachine?

    • Orthographic camera that adjusts it's orthographic size to always fit a group of objects, just like when you use a target group in the "Follow" field and a Framing Transposer on your virtual camera.
    • Contrary to the approach above, where the camera always fits the objects in the target group but also follows the target group around, I'd like the camera to have a fixed position, meaning it would just zoom in and out to fit everything but not move around.
    I tried out some stuff e.g. with invisible objects in the group that have a very high weight, with trying to restrict the camera with a very small confiner, etc. but nothing really produced the result I'm looking for.

    Is there a simple way to do this in Cinemachine?

    It wouldn't be too much work to write a simple script for a "normal" camera that does this. But I really like all the options you have with Cinemachine and would prefer to use that and not reinvent the wheel if possible.

    Thank you very much and have a nice day.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,946
    Out of the box, no, but you can easily do it with a little scripting.
    • Use a vcam with Do Nothing in both Aim and Body, which allows you to set its transform.
    • Set the LookAt target to the target group.
    • Write a custom CinemachineExtension that modifies the ortho size in response the the target group's bounding box.
    • You can use CinemachineFollowZoom as a starting point. Copy it, rename it, and modify the code to alter the state.Lens.OrthographicSize field in response to the TargetGroup.BoundingBox. Add the new extension to the vcam via the Extensions dropdown in the vcam inspector.
     
  3. Sharlatan

    Sharlatan

    Joined:
    Jul 23, 2013
    Posts:
    78
    Thank you very much for getting back to me in such a fast manner and providing me with a good idea of how to achieve the desired camera behavior!

    Unfortunately, I can't try it out right now, because I'm currently working on another piece of code I have to finish. That might take me a few more days. But after, I'll try out your idea and post my findings in this thread. Hopefully, they'll be useful to others as well!

    Thanks again and have a nice day.