Conflict Between Cinemachine and Pixel Perfect Camera During Smooth Zoom

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:

  1. Immediate Over-Zooming: The camera starts with a much closer view than the initial Orthographic Size set in the Cinemachine Virtual Camera.
  2. Pixel Perfect Camera Overrides Zoom: The Pixel Perfect Camera seems to override the zoom functionality, making smooth transitions impossible.
  3. 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
    );
}

}

I observed that too. It starts at z=0 and then pans out to the intended z=-10. I thought that was kinda neat way to start the scene, so I just left it as is.

This could have something to do with pixel snapping, the PPU (pixels per unit, quite low in your case) and something else I can’t recall. When I initially played around with these settings, I noticed I could drag a slider and given a certain value, suddenly the scale went from 1x to 2x just like that.

I wish I could tell you what it was, but I do recall having had a lower than 100 PPU initially. I set PPU back to 100 just as my sprites. My Cinecam now has an orthographic size of 0.5, and this is my PPC:

I’m on Unity 6 which may explain the difference.

1 Like

Thanks a lot for your suggestions! Unfortunately, they didn’t fully solve the problem. The zoom is working now, but it’s still a bit choppy. Do you have any other ideas?

Really appreciate your help!

Assuming the image can be aligned and pixel perfect at each end of the zoom, perhaps you could disable all the pixel perfect stuff while the camera is zooming, then re-enable it afterwards.

1 Like

Thank you so much for your advice! Disabling the Pixel Perfect Camera while zooming did help, and the zoom is working now. However, it’s still a bit choppy, so I need to refine it further.