I’m working on a 2D platformer project and instead of parallaxing scripts I was just using the perspective camera.
For confining I implemented 3D box collider confiners on a specific plane on the Z-axis.
Is this an acceptable use? Would I run across any problems later on due to this implementation?
That will work. It might be a little more efficient to do it with a custom extension on the vcam, such as this one:
using UnityEngine;
using Cinemachine;
/// <summary>
/// An add-on module for Cinemachine Virtual Camera that locks the camera's Z co-ordinate
/// </summary>
[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;
}
}
}
Excellent! I’ll implement this right away and have a look. Thanks lots!
1 Like