Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

CinemachineFreeLook Get X Axis and Y Axis values after force updating

Discussion in 'Cinemachine' started by Serhii-Horun, Aug 25, 2021.

  1. Serhii-Horun

    Serhii-Horun

    Joined:
    Apr 12, 2015
    Posts:
    151
    Hi!

    We have a problem. We need to translate transform position/rotation of current camera transform(which has not enabled cinemachine) to CinemachineFreeLook properties value(which it would have if we control via cinemachine).

    We found API InternalUpdateCameraState which force updating of camera state(which has properties
    OrientationCorrection, CorrectedPosition etc), but m_XAxis and m_YAxis are not being updated on CinemachineFreeLook. We use "inherite position = true" when trying to force update.
    Can you help us to get those m_XAxis and m_YAxis updated based on transform position/rotation in 1 frame?
    Thanks!
     
  2. Serhii-Horun

    Serhii-Horun

    Joined:
    Apr 12, 2015
    Posts:
    151
    Seems I've found solution:
    Code (CSharp):
    1. public void UpdateFreeLookProperties(Vector3 worldUp, float deltaTime = 0.01f)
    2.         {
    3.             if (Camera.main == null)
    4.             return;
    5.             var camera = Camera.main.transform;
    6.             var cameraPos = camera.position;
    7.             UpdateRigCache();
    8.             if (m_BindingMode != CinemachineTransposer.BindingMode.SimpleFollowWithWorldUp)
    9.                 m_XAxis.Value = mOrbitals[1].GetAxisClosestValue(cameraPos, worldUp);
    10.             m_YAxis.Value = GetYAxisClosestValue(cameraPos, worldUp);
    11.  
    12.             transform.position = cameraPos;
    13.             transform.rotation = camera.rotation;
    14.             m_State = PullStateFromVirtualCamera(worldUp, ref m_Lens);
    15.             PreviousStateIsValid = false;
    16.             PushSettingsToRigs();
    17.          
    18.             for (int i = 0; i < 3; ++i)
    19.                 m_Rigs[i].InternalUpdateCameraState(worldUp, deltaTime);
    20.             InternalUpdateCameraState(worldUp, deltaTime);
    21.         }
    That does that job.
    Then one more question: how to apply those update to camera transform? Seems state is being applied only after CinemachineCore/Brain triggers that(once per frame)?
     
  3. Serhii-Horun

    Serhii-Horun

    Joined:
    Apr 12, 2015
    Posts:
    151
    But it doesn't update Rigs:(
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    The easiest way to do this is to add to your non-CM camera a CinemachineExternalCamera component. This is a passive component that exposes your other camera to the CM world. Give it a high priority, so that it becomes the active vcam for CM while your other camera is active. Then enable the "Inherit Position" checkbox on your FreeLook. When the FreeLook is activated, it will automatically take the position of the outgoing vcam (which is your other camera, in this case).

    upload_2021-9-3_8-49-43.png

    upload_2021-9-3_8-50-20.png
     
    Serhii-Horun likes this.