- Home /
Change Camera Distance of Cinemachine(VirtualCamera)in script
Hello i want change the distance in the body section of virtualcinemachine: im trying to do this:
public CinemachineVirtualCamera vcam; public float distance; void Update() { vcam.GetCinemachineComponent<>().m_CameraDistance=distance; } (between the <> there is CinemachineFramingTransposer,i dont know why unityANSER dont let me put it in.) but it doesnt function, unity cant find CinemachineFramingTransposer. how can I get the distance via script? Thank you very much
Answer by xLorkin · Mar 21 at 01:08 PM
Hi,
I know this question is a bit old, but i stumbled upon the same problem and couldn't find an answer, so here it is:
If you are using 3rPersonFollow, try this:
var componentBase = moveCamera.GetCinemachineComponent(CinemachineCore.Stage.Body);
if (componentBase is Cinemachine3rdPersonFollow)
{
(componentBase as Cinemachine3rdPersonFollow).CameraDistance = cameraDistanceValue;
}
If you don't use 3rdPersonFollow, you can try printing the componentBase
, so you know what kind of object it is:
Debug.Log("componentBase = " + componentBase);