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;
}
}```