UnityRef is currently in early development. Some features may be incomplete and/or not functioning.

UNITYREF

Your Pit Stop For Solving ANYTHING in Unity

graphics

[Cinemachine] Programmatically Adjust Orbital Follow Position Damping

Solution

cinemachinecamera

Unity 2022.3.x - Unity 6.3.x

Published Thu, Mar 26

Issue

 Developers often encounter issues when attempting to modify camera smoothing at runtime in the updated Cinemachine 3.x API. The specific hierarchy of TrackerSettings within the CinemachineOrbitalFollow component is not immediately intuitive, leading to errors when trying to access PositionDamping directly.

Quick-Fix

To update tracking behavior, developers must access the TrackerSettings property on the CinemachineOrbitalFollow component and assign a new Vector3 to its PositionDamping field.

Expand Analysis

Access the CinemachineOrbitalFollow component to modify camera behavior at runtime.

  1. Include the Unity.Cinemachine namespace at the top of your script.
  2. Declare a reference to CinemachineOrbitalFollow and assign it via the Inspector or GetComponent().
  3. Access the TrackerSettings property of your script.
  4. Assign a new Vector3 value to the PositionDamping field within TrackerSettings.
  5. Use Vector3.zero to remove all smoothing for instant snapping, or use higher values to increase the lag/smoothing effect.

Additional Tips

  • The TrackerSettings values are applied during the camera’s internal update cycle; manual updates are not required after assignment.
  • In Unity 6, ensure you are using the updated Unity.Cinemachine namespace rather than the legacy Cinemachine namespace.
  • If you are targeting specific axes, you can modify the x, y, or z components of the Vector3 before assigning it back to TrackerSettings.PositionDamping.

Copy


using UnityEngine;
using Unity.Cinemachine;

public class CameraDampingController : MonoBehaviour
{
    [SerializeField] private CinemachineOrbitalFollow orbitalFollow;

    private void Update()
    {
        // Toggle snappy tracking when space is held
        if (Input.GetKeyDown(KeyCode.Space))
        {
            // Remove damping for immediate response
            orbitalFollow.TrackerSettings.PositionDamping = Vector3.zero;
        }
        else if (Input.GetKeyUp(KeyCode.Space))
        {
            // Restore default smoothing values
            orbitalFollow.TrackerSettings.PositionDamping = new Vector3(1f, 1f, 1f);
        }
    }
}

Related Posts Haven't quite found a solution to your problem? We think these posts might help you.

Content inspired by a Unity discussion post.