Search Unity

Applying the rotation of one virtual camera to another

Discussion in 'Cinemachine' started by EyeMD, Sep 10, 2021.

  1. EyeMD

    EyeMD

    Joined:
    Feb 28, 2015
    Posts:
    12
    Hi,
    I have a freelook camera that is used for my third person controller.
    I also have a "focus" virtual camera, that pops up onto the players shoulder only while the player locks onto a target. When the player stops focusing (releases trigger) the free look camera resumes.
    I use a state driven camera to switch between the two.

    The problem: I would like the freelook 3rd person camera to resume behind the character (in line with the focus cam) when the player is no longer focusing on a target (ie the character could rotate 180deg away while focusing on a target, then when they resume the free look camera the players view is facing the front of the character and it can be disorienting).

    I've tried copying the .m_Xaxis.value from the focus camera and copying it to the Free look camera once it resumes control but without success. How can I do this from code? Thanks so much
     
  2. EyeMD

    EyeMD

    Joined:
    Feb 28, 2015
    Posts:
    12
    Ok, so here's the work around I found:

    The player object can rotate 360 degrees (seen in its transform), and the free look camera can rotate 360 degrees (seen in its m_Xaxis.value)- ones value has no bearing on the other. If the player object (look at target) rotates, then the cameras Xaxis val stays the same.

    So after the freelook camera regains focus I just set its CinemachineFreeLook components xaxis value to the player objects rotation:

    thirdPersonCam.m_XAxis.Value = player.transform.rotation.eulerAngles.y;
     
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    Actually it depends on your FreeLook's Binding Mode. That controls the interpretation of the axis value. Have you tried setting this option in the FreeLook? That should give you what you're looking for, without any custom code.

    upload_2021-9-10_10-27-48.png