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

UNITYREF

Your Pit Stop For Solving ANYTHING in Unity

architecture

[Cinemachine] Snap <code>CinemachineOrbitalFollow</code> Instantly During Teleportation

Solution

cinemachineoptimizationcamerasrendering

Unity 2022.3.x - Unity 6.3.x

Published 2 days ago

Issue

 The CinemachineOrbitalFollow component fails to snap instantly when PositionDamping is active, resulting in a laggy transition during player teleportation. Additionally, the ForceCameraPosition rotation parameter often fails to override the internal orbital axis values.

Explanation

CinemachineOrbitalFollow maintains internal interpolation buffers to ensure smooth tracking. When PositionDamping is active, the component interprets a sudden change in position as a distance to be smoothed over time, rather than a discrete jump. Even when calling ForceCameraPosition, these damping values remain active, resulting in a visible slide toward the new coordinates.

To achieve an immediate snap:

  1. Access the CinemachineOrbitalFollow component on your script.
  2. Store the current PositionDamping values and then set them to Vector3.zero.
  3. Call the ForceCameraPosition method with the desired world space position.
  4. Restore the original PositionDamping values to resume smooth tracking.

In Unity 6 and Cinemachine 3.x, the preferred method for handling discrete jumps is notifying the camera system that a warp has occurred. This automatically clears all internal velocity and damping buffers for every component attached to the CinemachineCamera.

Additional Tips

  • Use the OnTargetObjectWarped method on the CinemachineCamera to synchronize all components, including CinemachinePositionComposer or CinemachineOrbitalFollow, with a single call.
  • If you need to snap the orbital rotation specifically, modify the HorizontalAxis.Value and VerticalAxis.Value properties directly, as ForceCameraPosition primarily handles the physical placement of the camera transform.
  • Ensure your script executes the teleport logic before the LateUpdate phase where Cinemachine typically processes its movement logic.
  • If the target is a Rigidbody, ensure the warp happens in FixedUpdate to maintain physics consistency before the camera updates.

TL;DR

To resolve interpolation lag, manually reset PositionDamping or invoke the OnTargetObjectWarped API to synchronize the camera with your script.


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.