I’d like to try and figure out a way to zoom in a camera view without actually physicall moving the camera itself. I’ve seen similar questions where people have just said to adjust the camera’s field of view property, but field of view is not the same as zoom. Changing the field of view actually changes the in-game perspective a bit so while it kind of looks “closer” that’s not actually what it does. It distorts things a bit which is not what I need.
Here is a camera zooming script i have made - attach it to any camera in your scene.
Press ‘w’ to zoom in, ‘s’ to zoom out.
var FOV : float=60;//don't change this
var zoomAcceleration : float=0.3;//How fast the camera zooms in and out
function Update () {
//If 'w' is held down, zoom in
if (Input.GetKey("w")){
FOV = FOV - zoomAcceleration;
camera.fieldOfView = FOV;
}
//If 's' is held down, zoom out
if (Input.GetKey("s")){
FOV = FOV + zoomAcceleration;
camera.fieldOfView = FOV;
}
//Don't let the Field Of View go below 1
if (FOV<=1){
FOV=1;
}
//Don't let the Field Of View go above 60
if (FOV>=60){
FOV=60;
}
}