Course contentsShow
← Unity Game Development
Lesson 403 of 8286. Animation and CinemachineFree lesson

Locking Camera Rotation with Cinemachine Position Constraints

You will utilize position and rotation constraints to force the virtual camera to maintain specific orientations relative to moving targets.

Locking Camera Rotation with Cinemachine Position Constraints

In this lesson, you will learn how to use Cinemachine Position Constraints to force your Virtual Camera to maintain a fixed relative rotation regardless of its target's chaotic movement.

The Problem of Target Rotation

When you use a standard Look At target for a Virtual Camera, the camera constantly rotates to track that object. While this is great for fluid movement, sometimes you need a "locked" perspective—for example, a side-scrolling platformer or a top-down view where the camera must ignore the target’s specific rotation (like a character turning around) and maintain a consistent, stable frame.

Implementing the Constraint

Instead of letting the Look At property handle the orientation, we use a Cinemachine Position Constraint. This component allows you to anchor the camera's position relative to a target while explicitly defining a constant rotation offset.

By adding a CinemachinePositionConstraint extension to your Virtual Camera, you can set the Maintain Offset property. When enabled, the camera locks its position relative to the target's origin point at the moment of activation. To prevent the camera from inheriting the rotation of the target (which would cause the view to spin as the character turns), you configure the constraint to ignore the target’s rotation axis.

You can set this up directly in the Inspector:

  1. Select your Virtual Camera.
  2. Add the CinemachinePositionConstraint extension.
  3. Assign your target to the Target field.
  4. Set the Update Method to LateUpdate to ensure the camera tracks after the character’s movement script has finished.
  5. In the Rotation Offset field, define your desired permanent angle (e.g., 0, 0, 0 for a perfectly locked side-on view).

By decoupling the rotation from the target's transformation, you ensure that even if your character does a 180-degree flip, your camera remains perfectly steady, providing a professional, polished cinematic feel to your game’s perspective.

Key Takeaway: Use Cinemachine Position Constraints to override dynamic Look At behaviors, allowing you to maintain a static, locked orientation while still keeping the camera anchored to a moving subject.