Using the newer FPS StarterAssets

You can’t change the FOV on the MainCamera as it is being overridden by the Cinemachine Brain.

Instead you can reference the CinemachineVirtualCamera which on the newer Starter Assets is called PlayerFollowCamera. then change the FOV on its Lens property.

[SerializeField] CinemachineVirtualCamera fovCamera;

{
                zoomedInToggle = true;
                fovCamera.m_Lens.FieldOfView = zoomedInFOV;
            } 
else
            {
                zoomedInToggle = false;
                fovCamera.m_Lens.FieldOfView = zoomedOutFOV;
            }



Not sure if this is the correct way of doing it but, it has minimal changes from Ricks implementation.

1 Like

Also to note…

When setting up the PlayerFollowCamera (using the new First Person controller assets), make sure the the follow camera is not inside the Capsule (default). When you zoom in on the camera, if it is inside the object, it may not work properly. just make sure it is somewhat outside the gameobject

I used a Youtube tutorial (pointed by Nina) to fix the issue of weapons clipping through walls when close. I’m not sure if this is the cause, but getting into the zooming lecture, I am able to alter the Cinemachine FOV (same solution as above), but I think because I have one camera looking at the gun and another looking at the world to prevent the clipping, the zoom doesn’t affect the weapon. It looks the same size whether zoomed in or not. Does anyone have a solution?

Edit: Never mind! I had another look at the other tutorial and realised there was another camera in the children, so I accessed it via a SerializeField and set separate zoom variables for it (since its default FOV was different to the main camera’s).

CinemachineVirtualCamera mainCamera;
    [SerializeField] Camera weaponCamera;
    [SerializeField] int zoomOutFOV = 40;
    [SerializeField] int zoomInFOV = 20;
    [SerializeField] int weaponZoomOutFOV = 60;
    [SerializeField] int weaponZoomInFOV = 40;
    bool zoomed = false;
    void Start()
    {
        //weaponCamera = GetComponentInChildren<Camera>();
        mainCamera = GetComponentInChildren<CinemachineVirtualCamera>();
    }

    void Update()
    {
        if (Input.GetMouseButtonDown(1))
        {
            if (zoomed == false)
            {
                mainCamera.m_Lens.FieldOfView = zoomInFOV;
                weaponCamera.fieldOfView = weaponZoomInFOV;
                zoomed = true;
            }
            else if (zoomed == true)
            {
                mainCamera.m_Lens.FieldOfView = zoomOutFOV;
                weaponCamera.fieldOfView = weaponZoomOutFOV;
                zoomed = false;
            }
        }```

Privacy & Terms