Using AOV instead of FOV might help!
public var minFOV : float = 1;
public var baseFOV : float = 0;
public var czoom : float = 0;
function Start ()
{
baseFOV = Camera.main.fieldOfView;
}
function Update ()
{
//Step one: Calculate the percentage of the maximum zoom that should be used (this is actually the perscentage of the maximum AOV (area of view)
if (Input.GetMouseButton(1))
czoom = Mathf.Lerp(czoom, 0.0, Time.deltaTime);
else
czoom = Mathf.Lerp(czoom, 1.0, Time.deltaTime);
//Step two: Calculate the wanted Aov from our zoom percentage
var maxAov : float = FOVtoAOV(baseFOV, Camera.main);
var minAov : float = FOVtoAOV(minFOV, Camera.main);
var aov : float = Mathf.Lerp(minAov, maxAov, czoom);
//Step three: Calculate the corresponding FOV for our wanted AOV
var fov : float = AOVtoFOV(aov, Camera.main);
//Step four: Apply the fov!
Camera.main.fieldOfView = fov;
}
function FOVtoAOV(fov : float, cam : Camera)
{
return (fov/90.0) * cam.farClipPlane;
//At 90 degrees the width of the AOV will be directly proportional to the distance of the camera
}
function AOVtoFOV(aov : float, cam : Camera)
{
return (aov/cam.farClipPlane)*90.0;
//When our AOV equals the farClipPlane, the FOV will be 90 degrees
}
Let me know how this works! :) You may have to fine tune the speeds as it does zoom out rather quickly -- but zoom speed slows down as you get to smaller zoom : D
↧