-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLockCameraY.cs
More file actions
24 lines (20 loc) · 756 Bytes
/
LockCameraY.cs
File metadata and controls
24 lines (20 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using UnityEngine;
using Unity.Cinemachine;
public class LockCameraY : CinemachineExtension
{
[SerializeField] private float lockedYPosition = 5f;
protected override void PostPipelineStageCallback(
CinemachineVirtualCameraBase vcam,
CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
{
if (stage == CinemachineCore.Stage.Body)
{
// Get the position Cinemachine ALREADY calculated (which includes following the player's X)
Vector3 pos = state.RawPosition;
// Only overwrite the Y. Leave X and Z exactly as Cinemachine calculated them.
pos.y = lockedYPosition;
// Apply it back
state.RawPosition = pos;
}
}
}