I have been using the following code to restrain the camera movement on the z-axis.
Previously on Cinemachine 2.3.4 all went fine but today I wanted to upgrade to 2.6.0 due to some bug fixes
But my script no longer has any effect. What is the new recommended way to confine the camera on a specific axis?
using UnityEngine;
using Cinemachine;
/// <summary>
/// An add-on module for Cinemachine Virtual Camera that locks the camera's Z co-ordinate
/// </summary>
[ExecuteInEditMode]
[SaveDuringPlay]
[AddComponentMenu("")] // Hide in menu
public class LockCameraZ : CinemachineExtension
{
[Tooltip("Lock the camera's Z position to this value")]
public float m_ZPosition = 10;
protected override void PostPipelineStageCallback(
CinemachineVirtualCameraBase vcam,
CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
{
if (stage == CinemachineCore.Stage.Body)
{
var pos = state.RawPosition;
pos.z = m_ZPosition;
state.RawPosition = pos;
}
}
}