SOLVED! Changing Tracking object offset of freelook cinemachine from script

Hello gurus!

I am trying to change the tracking object offset of the middle rig in the freelook cinemachine camera from script, but I can’t find anywhere in the docs a way to access this property. Does anyone here knows how to access this property or can point me in the right direction?

Thanks in advance

Regards,
Carlos

Well just in case that someone else need this as I did, here is how to do it:

using Cinemachine;// Add Cinemachine namespace

You have to create these variables, name them however you want:

GameObject camObj;//This is your camera with the free look component on it

CinemachineFreeLook freeLook;// this reference the free look component in your camera

CinemachineComposer comp;//I named this variable comp for “Composer”, you can name it however you like. This is the cinemachine component with all the aiming stuff on it

then in Start Method:

void Start()
{

camObj = GameObject.FindWithTag(“MainCamera”);

freeLook = camObj.GetComponent();

comp = freeLook.GetRig(1).GetCinemachineComponent();

comp.m_TrackedObjectOffset.y = “your value here”;// This is how you get to “Tracked Object Offset” of the rig as well as any other property in the rigs.

}

12 Likes

Thank you, it helped me.

@strongbox3d Do you know how to smoothen out the transition when changing the offset? With the code above it’s a hard cut.

@JacquesJ Changes to TrackedObjectOffset are instantaneous, while camera movement as a result of target movement is subject to damping. So you can either make a gradual change to the offset, or you can use an invisible child object as your target, placed at the desired offset, and just reposition it. If vcam has damping, it will move gradually.

1 Like

@Gregoryl thanks that works perfectly!

Thanks this was very helpful in 2021!

My only issue is that I don’t use Freelook and I have zero idea what is supposed to be the main camera.