- Home /
FOV bugged, i think
Hello, I am practicing unity and I wanted to try to zoom with the weapon, but this happens video my code would be the following:
void OnScope()
{
float factor = 2.0f * Mathf.Tan(0.5f * originalFov * Mathf.Deg2Rad);
float zoomedFOV = 2.0f * Mathf.Atan(factor / (2.0f * magnification)) * Mathf.Rad2Deg;
animator.SetBool("IsScope", scope);
cam.fieldOfView = Mathf.Lerp(cam.fieldOfView, zoomedFOV, scopeFovTime * Time.deltaTime);
movement.movementMultiplier = scopeMovementMultiplier;
}
void OnUnscope()
{
animator.SetBool("IsScope", scope);
cam.fieldOfView = Mathf.Lerp(cam.fieldOfView, originalFov, scopeFovTime * Time.deltaTime);
movement.movementMultiplier = originalMovementMultiplier;
}
Comment
Here is the resto of my code, i call MyInput from Update:
public void MyInput()
{
if (isReloading)
return;
shooting = Input.GetKey(KeyCode.Mouse0);
if (Input.GetKey(KeyCode.Mouse1))
{
scope = true;
}
else
{
scope = false;
}
if (Input.GetKeyDown(KeyCode.R) && bulletsLeft < magazineSize && !isReloading && canReload)
{
StartCoroutine(Reload());
return;
}
if (bulletsLeft <= 0 && shooting)
StartCoroutine(Reload());
//Shoot
if (readyToShoot && shooting && !isReloading && bulletsLeft > 0)
{
Shoot();
}
if (scope)
{
OnScope();
}
else
{
OnUnscope();
}
}
Your answer
Follow this Question
Related Questions
Clamp camera to multiple on-screen players 0 Answers
Lens Effect 1 Answer
Strange results when using Context Menu and Camera 2 Answers
Can I change the FOV of the Editor window(s) camera(s)? 0 Answers