For those who are using Unity 6 and Cinemachine 3.1,
1. “Follow” and “Hard Look At” Components
For old Cinemachine’s “Body” and “Aim”, I used “Follow” and “Hard Look At” Components to replace them.
CinemachineCamera -> Procedural Components -> Position Control -> Follow (Component) CinemachineCamera -> Procedural Components -> Rotation Control -> Hard Look At
2. For accessing “Follow Offset”, Use “CinemachineFollow” component
using Unity.Cinemachine;
private const float MIN_FOLLOW_Y_OFFSET = 2f;
private const float MAX_FOLLOW_Y_OFFSET = 12f;
[SerializeField] private CinemachineFollow cinemachineFollow; // Just used the Cinemachine Camara object
private Vector3 targetFollowOffset;
private void Start() {
targetFollowOffset = cinemachineFollow.FollowOffset;
}
private void Update() {
var zoomAmount = 1f;
var zoomSpeed = 5f;
if (Input.mouseScrollDelta.y > 0) {
targetFollowOffset.y -= zoomAmount;
}
if (Input.mouseScrollDelta.y < 0) {
targetFollowOffset.y += zoomAmount;
}
targetFollowOffset.y = Mathf.Clamp(targetFollowOffset.y, MIN_FOLLOW_Y_OFFSET, MAX_FOLLOW_Y_OFFSET);
cinemachineFollow.FollowOffset = Vector3.Lerp(cinemachineFollow.FollowOffset, targetFollowOffset, Time.deltaTime * zoomSpeed);
}
The original code was from @UnityCodeMonkey’s tutorial, and I modified it to fit the new Cinemachine.
4. Extra thoughts during development
Input.mouseScrollDelta is an event-based input and resets every frame, which can cause missed scroll events when scrolling quickly. Using Input.GetAxis(“Mouse ScrollWheel”) could provide more reliable detection.
Cache the component reference when possible to improve performance and readability.