Rotation offset for virtual camera

Hello all,

I have a question, I’m trying to figure out how to add rotation to a virtual camera.
since cinemachine controls the rotation… is there an extension similar to offset, but for rotation?

Not out of the box, no, but you can take CinemachineCameraOffset.cs, copy it, and modify it to affect state.OrientationCorrection instead of state.PositionCorrection. The units are in camera-local space.

Thanks! you helped me a lot!

here’s a quick summery if anyone needs:

  1. go to packages > Cinemachine > Runtime > Behaviours
  2. Open “CinemachineCameraOffset.cs” and copy the script.
  3. Create a new script “CinemachineCameraRotation.cs” and paste the code(make sure to rename the class as well).
  4. replace “state.PositionCorrection += offset;” with “state.OrientationCorrection *= Quaternion.Euler(offset);”.
  5. add this as an extension.
3 Likes

Thanks rubiez64 - I was totally happy when I found your post after hours of trying to get some rotation offset to my virtual camera!

I would like to recommend to add a script like that to the official cinemachine package. There might be other users who really need it.

1 Like

Hey guys, I know it’s old but the problem with rubiez64 solution is that the rotation offset will be in world space and not in local space of the camera, so when the camera will turn it will rotate in the wrong direction :confused:

Use it :slight_smile:

protected override void PostPipelineStageCallback(
    CinemachineVirtualCameraBase vcam,
    CinemachineCore.Stage stage,
    ref CameraState state,
    float deltaTime
) {
    if (stage != applyAfter) {
        return;
    }

    state.RawOrientation = state.RawOrientation.ApplyCameraRotation(offset, state.ReferenceUp);
}
1 Like

Work for me !!! Thanks

Sorry for asking, I’m stucked at ‘add this as an extension’. Or maybe I’ve done wrong processing step 2.
How do I solve this…?


For test, I copied ‘CinemachineCameraOffset.cs’ and changed script & class name. Same error occured.
This is Unity 2022.3.22f1, thanks!

You seem to be having issues with the Cinemachine namespace.

  • Which version of Cinemachine are you using? (open the Package Manager to check)
  • Does your project have an asmdef file? If so, you’ll need to add Cinemachine to it in order to be able to use the Cinemachine namespace.

As an experiment, try adding this test script. Does it produce errors?

using UnityEngine;
using Cinemachine;

public class TestNamespace : MonoBehaviour
{
    public CinemachineVirtualCamera Vcam;
}