I was following a tutorial on youtube to remake angry birds and it used Cinemachine Camera to follow the player and enemies. However when it zooms out, the camera pans super low on the Y axis and looks like this.
I would much rather have it pan upwards. than to go beneath the ground like this. I tried writing a script to keep the position locked at 0 but it doesn’t work. I used Debug.Log() to check that my code is running and it is.
You can write a custom CM extension for the vcam. Here is one that locks the camera Y to a fixed position. You can modify it to implement a minimum value 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;
}
}
}