Change Focal Length of virtual camera in runtime

Hello! I’m currently using cinemachine 2.5.0, and I’m trying to change the focal length of my virtual camera in runtime, I’ve noticed you can only access to the Field of view variable through the lens settings of the CinemachineVirtualCamera, but there is no focal length variable, I’ve also noticed that you can have a preset for your virtual camera where you can adjust the focal length, but I can’t find a way to access the current lens preset of the virtual camera to set a custom focal length. Is there any way that I could change the focal length via script?

Thank you.

Ok, It seems I managed to fix this thanks to this old post: Virtual Production and Cinematography with Cinemachine: Suggested Additions

Using this function I converted the Focal length I wanted to a FOV value and set it on the m_Lens.FieldOfView variable:

float FocalLengthToVerticalFOV(float focalLength)
        {
            if (focalLength < 0.001f)
                return 180f;
            return Mathf.Rad2Deg * 2.0f * Mathf.Atan(Lens.SensorSize.y * 0.5f / focalLength);
        }
1 Like