Title: Conflict Between Cinemachine and Pixel Perfect Camera During Smooth Zoom
Description:
I’m facing an issue where Cinemachine Virtual Camera and Pixel Perfect Camera conflict in my 2D Unity project during smooth zoom transitions. The zoom works perfectly without the Pixel Perfect Camera, but when it is added to the Main Camera, the following problems occur:
- Immediate Over-Zooming: The camera starts with a much closer view than the initial
Orthographic Size
set in the Cinemachine Virtual Camera. - Pixel Perfect Camera Overrides Zoom: The Pixel Perfect Camera seems to override the zoom functionality, making smooth transitions impossible.
- Loss of Pixel Perfect Rendering During Zoom: I want the game to remain pixel-perfect at the start and end of the zoom, even if it’s temporarily lost during the transition.
using UnityEngine;
using Cinemachine;
[RequireComponent(typeof(CinemachineVirtualCamera))]
public class CinemachineZoom : MonoBehaviour
{
public CinemachineVirtualCamera virtualCamera;
public float zoomSpeed = 2f;
public float minZoom = 8.4375f;
public float maxZoom = 33.75f;
public float smoothSpeed = 5f;
private float targetZoom;
void Start()
{
targetZoom = virtualCamera.m_Lens.OrthographicSize;
}
void Update()
{
float scroll = Input.GetAxis("Mouse ScrollWheel");
if (scroll != 0f)
{
targetZoom -= scroll * zoomSpeed;
targetZoom = Mathf.Clamp(targetZoom, minZoom, maxZoom);
}
virtualCamera.m_Lens.OrthographicSize = Mathf.Lerp(
virtualCamera.m_Lens.OrthographicSize,
targetZoom,
Time.deltaTime * smoothSpeed
);
}
}