I want to take only the rotation of the Y axis, not the X and Z axes, without constraining the posit

I’m using the FreeLook camera. When the FreeLookCamera sees the LookAt, I don’t want to constrain the position of the FreeLookCamera camera, only rotate the Y axis. What method should I take?

In that case you should use a simple virtual camera:

8959275--1230744--upload_2023-4-19_7-22-17.png

Is there a way to keep the FreeLook control but exclude the rotation of the X and Z axes only for the gaze?

You can keep the FreeLook and put DoNothing in Aim for Top, Middle, and Bottom rigs. That will allow the camera to orbit, but its rotation will remain constant. Then, you can add a custom Aim behaviour to rotate the camera Y only.

Alternatively, you can make a custom extension to lock the X and Z rotation of the camera. Here is one that locks the Y position. You can modify it to lock the X and Z rotations instead.

using UnityEngine;
using Cinemachine;

/// <summary>
/// An add-on module for Cinemachine Virtual Camera that locks the camera's Y co-ordinate
/// </summary>
[SaveDuringPlay] [AddComponentMenu("")] // Hide in menu
public class LockCameraY : CinemachineExtension
{
    [Tooltip("Lock the camera's Y position to this value")]
    public float m_YPosition = 10;

    protected override void PostPipelineStageCallback(
        CinemachineVirtualCameraBase vcam,
        CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
    {
        if (stage == CinemachineCore.Stage.Finalize)
        {
            var pos = state.RawPosition;
            pos.y = m_YPosition;
            state.RawPosition = pos;
        }
    }
}

Thanks for the nice class, but the camera shakes when moving up and down. Can you tell me what’s wrong with my code?

public class AltavaCamYLook : CinemachineExtension
{
    protected override void PostPipelineStageCallback(CinemachineVirtualCameraBase vcam, CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
    {
        if (stage == CinemachineCore.Stage.Finalize)
        {
            var pos = vcam.LookAt.position;
            pos.y = vcam.transform.position.y;
            vcam.LookAt.position = pos;
        }
    }
}

I am confused about what you’re trying to do. I thought you wanted to constrain the camera rotation, but instead you are constraining the position.

Are you looking for a camera that rotates around the player only horizontally but not vertically? If so, then replace the FreeLook with a VirtualCamera set up like this:

8964654--1231896--upload_2023-4-21_7-37-2.png

If that is not what you want, please describe the desired camera behaviour more carefully. A picture or diagram would be helpful.

The shape of the camera I want to do is to limit the camera’s line of sight while maintaining the range of motion of the prelook.

If you look at the picture, the red arrow is the current pre-look and the blue arrow is the direction I want to see.
.

I think I’ve found a way! However, there is a small problem. Is there any way to access the LookAtOverride of the red box area using script?

It would be freeLook.GetRig(n).LookAt, where n = 0…2

Any help is greatly appreciated Thank you for your support!