Freelook camera stuck in the same rotation as lookat/follow started in

If I enable my freelook camera when my follow/lookat is rotated, say he is standing on uneven ground and his rotation transform is [0, 0, 27], then the camera will correctly adapt and also rotate. However, it is then stuck in that rotation, and does not go back to [0, 0, 0] when the floow/lookat does, so it is super disorienting running around with a tilted camera.



It’s because of this:

4897367--473630--upload_2019-8-26_11-4-51.png

Set it to LockToTarget instead.

Ah I see I was worried that was why. This mode really doesnt work for me since the animations I use on the character can be a bit wobbly, so the camera wobbles too much.

Maybe I can just add a script to the camera that will set Z rotation to 0 if its not 0.

What if you just added more angular damping on roll?

I would have to put Pitch, yaw and roll to about 10, but that causes some other issues where the camera keeps panning after stopping due to too much smoothing.

This is not something I expect Cinemachine to fix since its due to poor animation work. Is there any way to access the Z rotation? Cant find it, and editing it in editor does nothing.

You can’t manually change the vcam’s transform, as it is controlled by the vcam script which will always overwrite what you put.

How about using the LockToTargetWithWorldUp binding mode?

I’ve tried them all with all types of damping, the only one that feels good is Lock to target on assign =/ It requires so much damping that the camera literally does half a lap around the character before stopping when Im turning.

So there is no way to manipulate the vcams z axis? Or just a setting that locks the z rotation at 0.

LockToTargetWithWorldUp locks the Z rotation. I’m not really sure what behaviour you’re looking for when the character is tilted. Maybe you can have a dummy game object that tracks the target but orients itself the way you want, and use that as a vcam target.

You could also try writing a custom CinemachineExtension to rotate the vcam.

I want it to behave exactly like Lock to target on assign, but without moving on the z axis.
That is a great idea for the dummy game object, Ill try that.

I sent you an example scene if you want to see what I mean. In the meantime, I added this script to the camera target (target is a child object at the center of the player model). And seems to solve it :slight_smile:

private void LateUpdate()
{
var rotationVector = transform.rotation.eulerAngles;
rotationVector.z = 0;
transform.rotation = Quaternion.Euler(rotationVector);
}
1 Like

Is there any docs on how to do this?

Unfortunately my solution posted above does not always work… When transitioning from one camera back to my freelook cam the z value is still not 0 for some reason, which makes no sense to me. I do this to my camera target so Z should always be world 0, independent of the parent (my players) rotation.

private void Update()
    {
        Vector3 parentSpaceUp = transform.parent.gameObject.transform.InverseTransformDirection(Vector3.up);
        transform.localRotation = Quaternion.LookRotation(Vector3.forward, parentSpaceUp);
    }

The best docs on CinemachineExtension are the source files for the extensions that ship with Cinemachine. Your extension needs to set state.RawOrintation to have zero Z rotation.

As for why your dummy child object solution is not working, I really don’t know. Can you prove that the invisible game object really has 0 Z rotation, say by attaching a cube or some shape to it so that it becomes visible?