Changing Cinemachine Position Damping in Script

I’m reading through the current documentation and unfortunately I am unable to understand how to change the values for the position damping on my Cinemachine Camera through script. For simplicity sake, I’m just looking to change the damping values when I press a button. Thank you for your time.

What does that mean?

Have you found the section in the documentation related to this feature?

If so, why haven’t you included that link in your post?

If you haven’t found it, what are the specific terms you have looked for?

If you have found what you want, is it that you simply cannot get it to work?

Are you not able to understand the syntax necessary?

Or if you understand the syntax is it just not working?

Have you verified your code is running and debugged the values involved?

All of those imply vastly different solutions and answers.

Try this handy template for reporting technical issues:

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, log output, variable values, and especially any errors you see
  • links to actual Unity3D documentation you used to cross-check your work (CRITICAL!!!)

The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?

If you post code, only post the relevant code and always use the format button above. Do not post photographs of code.

These are the pages I read through:

  1. Cinemachine Follow component | Cinemachine | 3.1.3.
  2. Field Damping | Cinemachine | 3.0.1
  3. Interface CinemachineFreeLookModifier.IModifiablePositionDamping | Cinemachine | 3.1.3
  4. Class CinemachineFreeLookModifier.PositionDampingModifier | Cinemachine | 3.1.3
  5. Apply transposer damping to custom cinemachine extension.

Along with these outdated videos, hoping I could work backwards from them but it seems that the architecture between 2 and 3 is changed significantly:

  1. https://www.youtube.com/watch?v=PHx59Cxob2s&t=42s
  2. https://www.youtube.com/watch?v=wvPbSRTaH1I&t=591s

As well as these videos about Cinemachine 3 that unfortunately did not cover the topic:

  1. https://www.youtube.com/watch?v=znOii5cz0RU&t=19s
  2. https://www.youtube.com/watch?v=4xd37R1spKw&t=891s
  3. https://www.youtube.com/watch?v=wB-EQH7jvFY

I frankly could not figure out how to properly reference the damping variables using everything here, and was looking for something like this:

public class SwapCharacter : MonoBehaviour
{
    public CinemachineCamera cinemachineCam;
    public ThirdPersonCam thirdPersonCam;
    
    //Reference to damping variables
    
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Q))
        {
            //Set to 0
        }
        if (Input.GetKeyDown(KeyCode.F))
        {
            //Set to 1
        }
    }

It’s exactly like all other Unity stuff… drag it in and access the field you want.

// drag this in...
public CinemachineThirdPersonFollow follow;

Then to change damping (all axes at once):

// Set to 0
follow.Damping = Vector3.one * 0.0f;

or…

// Set to 1
follow.Damping = Vector3.one * 1.0f;

Tested just now in CM3.1.3 and damping is wildly different between 1.0 and 0.0f, so I’m thinking “it works.”

Try it yourself in the enclosed Unity6-compatible package:

Fnord.unitypackage (20.5 KB)

EDIT: you’ll need the new input system, or just hack the script back to the old input system you have.

I needed to access the Orbital Follow component, but I got it working

using Unity.Cinemachine.TargetTracking;

public CinemachineOrbitalFollow orbitalFollow;

void Update()
    {
        if (Input.GetKeyDown(KeyCode.Q))
        {
            orbitalFollow.TrackerSettings.PositionDamping = Vector3.one * 0;
        }
        if (Input.GetKeyDown(KeyCode.F))
        {
             orbitalFollow.TrackerSettings.PositionDamping = Vector3.one;
        }
    }