Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

every time the game started my FOV of cinemachine virtual cam always become 0 in unity

so im trying to make an aiming mechanic on my game with unity engine, it works well. but the problem is every time the game started, the FOV always become zero. it will be normal again when i press right click on my mouse.

here is my code:

[Header("Zoom")]
public float zoomInFov = 40;
[HideInInspector] public float hipFov;
[HideInInspector] public float currentFov;
public float fovSmoothSpeed = 10;

void Start()
{
    hipFov = vCam.m_Lens.FieldOfView;
}

//Aiming
if (Input.GetMouseButton(1))
{
    animator.SetBool("isAiming", true);
    currentFov = zoomInFov;
}

if (Input.GetMouseButtonUp(1))
{
    animator.SetBool("isAiming", false);
    currentFov = hipFov;
}
vCam.m_Lens.FieldOfView = Mathf.Lerp(vCam.m_Lens.FieldOfView, currentFov, fovSmoothSpeed * 
Time.deltaTime);

please help me, i’d appreciate any advice 🙂

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

void Start()
{
    hipFov = vCam.m_Lens.FieldOfView;
    currentFov = hipFov;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading