Hi everyone. I am making a game in which you have a player that needs to go up a big tower by jumping.
I use a cinemachine virtual camera to follow the player around when he jumps and falls. I now ran into the problem that the camera also follows the player when moving in the x-axis when instead i would like to have the camera be locked to x = 0. I found a script that is supposed to work from someone that had a similar problem.
using UnityEngine;
using Cinemachine;
/// <summary>
/// An add-on module for Cinemachine Virtual Camera that locks the camera's X co-ordinate
/// </summary>
[ExecuteInEditMode]
[SaveDuringPlay]
[AddComponentMenu("")] // Hide in menu
public class cameralock : CinemachineExtension
{
[Tooltip("Lock the camera's X position to this value")]
public float m_XPosition = 0;
protected override void PostPipelineStageCallback(
CinemachineVirtualCameraBase vcam,
CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
{
if (stage == CinemachineCore.Stage.Body)
{
var pos = state.RawPosition;
pos.x = m_XPosition;
state.RawPosition = pos;
}
}
}
This doesn’t do anything for me though. Anyone know why that might be the case?
Thanks in advance