Virtual Camera accessing Aim and Body properties through Script

I am trying to access the Follow offset in Body, and Vertical/Horizontal axis value range in aim through script to change it during runtime or just get the value. Currently unsure how to do it.

1 Like

Got this sorted out.:

Aim and Body Properties have various subsection like Transposer, POV etc. as listed in the below documents.
https://docs.unity3d.com/Packages/com.unity.cinemachine@2.2/manual/CinemachineVirtualCameraAim.html
https://docs.unity3d.com/Packages/com.unity.cinemachine@2.2/manual/CinemachineVirtualCameraBody.html

First get the component which has been set in Aim and/or Body and then access the variable:
playerFPVCamera.GetCinemachineComponent().m_VerticalAxis.m_MaxSpeed

8 Likes

Hey there thanks for the explanation but I’m not sure how to use this information, could you elaborate a bit? I can’t find a way to access body properties via script

Install the Cinemachine sample scenes from the package manager. Inside, you will find a scene called “Scripting”. In there, there is a ScriptingExamples.cs file, which shows an example of this.

2 Likes

If that may help anyone I found a the solution at the end of this thread, there is a function to force the position of the VCam from whatever type of Body you use, in my case I use the Transposer so all I had to do was

CinemachineTransposer transposer = cam.GetCinemachineComponent();
transposer.ForceCameraPosition(Vector3.zero, Quaternion.identity);

Thanks everyone for the help!

2 Likes

You’re supposed to call that method on the vcam, not on the vcam’s individual components. I don’t know what you’re trying to do or what this call did for you, but if it worked it was probably just accidental.

hello! i want to smoothdamp the orthographicsize on virtual camera, what would be the code for that?
currently i am using this:

vcam.m_Lens.OrthographicSize = Mathf.SmoothDamp(vcam.m_Lens.OrthographicSize, 5.25f, ref velZoom, .2f);

but this doesn’t damp or do anyhthing. But when i give it a solid value, it changes the size but without damping.
like so:

vcam.m_Lens.OrthographicSize = 5.25f;

plz help :frowning:

Try this:

var lens = vcam.m_Lens;
lens.OrthographicSize = Mathf.SmoothDamp(lens.OrthographicSize, 5.25f, ref velZoom, .2f);
vcam.m_Lens = lens;
1 Like

bro can i access the virual camera inside aim property horizonatal axis value thorugh scirpt it is not showing the instance m_XAxis or anything like that but in free look camera it is showing m_XAxis how can i do same in the virtual camera

You have to access the Cinemachine component inside the vcam component. For example, if the Body setting is OrbitalTransposer, you would do something like this:
vcam.GetCinemachineComponent<CinemachineOrbitalTransposer>().m_XAxis.Value = bla;

1 Like