Search Unity

Syncing multiple camera's rotations

Discussion in 'Cinemachine' started by will_unity257, Feb 15, 2021.

  1. will_unity257

    will_unity257

    Joined:
    Dec 30, 2020
    Posts:
    3
    Hey. I have a CinemachineStateDrivenCamera setup with 3 cameras at different zoom levels (just adjusting the Follow Offset for each camera). They're Orbital Transposer cameras, FWIW.

    I've got a camera switcher script on the CinemachineStateDrivenCamera which iterates through the vCams and matches up their x rotations each time the camera switches. It works, but feels kinda clunky. Is there a better way to do it - maybe a no code solution?!

    Code (CSharp):
    1. private void SwitchCamera(bool zoomingIn)
    2.     {
    3.         References.theCamera = csdc.LiveChild;
    4.         CinemachineVirtualCamera vCam = (References.theCamera as CinemachineVirtualCamera);
    5.  
    6.         // get the current vcam's rotation
    7.         float targetX = vCam.GetCinemachineComponent<CinemachineOrbitalTransposer>().m_XAxis.Value;
    8.         var children = csdc.ChildCameras;
    9.         // sync all the child cameras' rotations
    10. foreach (var cam in children)
    11.         {
    12.             var transposer = (cam as CinemachineVirtualCamera).GetCinemachineComponent<CinemachineOrbitalTransposer>();
    13.             transposer.m_XAxis.Value = targetX;
    14.         }
    15.  
    16.         animator.SetBool("Zoomed", zoomingIn);
    17.         References.theCamera = csdc.LiveChild;
    18.     }
    Thanks in advance!
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
  3. will_unity257

    will_unity257

    Joined:
    Dec 30, 2020
    Posts:
    3
    Perfect! Thank you! You're a Rockstar answering all the questions on here
     
    marc_tanenbaum and Gregoryl like this.
  4. yazoubello

    yazoubello

    Joined:
    Jan 5, 2021
    Posts:
    9
    Last edited: Feb 27, 2021