- Home /
Increase camera Zoom
Hello guys, I have this script which zoom the camera to a field of view of 1, But its not enough for my scene. My scene is huge. How Do I make the camera to zoom to a longer distance.
My script is below,
var zoom : int = 20;
var normal : int = 60;
var smooth : float = 5;
private var isZoomed = false;
function Update () {
//if(Input.GetKey("z")){
if(Input.GetAxis("Mouse ScrollWheel")){
isZoomed = !isZoomed;
}
if(isZoomed == true){
camera.fieldOfView = Mathf.Lerp(camera.fieldOfView,zoom,Time.deltaTime*smooth);
}
else{
camera.fieldOfView = Mathf.Lerp(camera.fieldOfView,normal,Time.deltaTime*smooth);
}
}
Answer by giudark · Jan 23, 2014 at 06:50 PM
Here you can find many "famous" camera script : Scripts/Controllers In particular i suggest you to adopt MouseOrbitZoom without the orbit part if you don't want it:
public Transform target;
public float distance = 10f;
public float maxDistance = 100;
public float minDistance = 5f;
public int zoomRate = 40;
public float zoomDampening = 5.0f;
private float currentDistance;
private float desiredDistance;
private Vector3 position;
public void Start(){
if (!target){
var go = new GameObject("Cam Target");
go.transform.position = transform.position + (transform.forward * distance);
target = go.transform;
}
currentDistance = distance;
desiredDistance = distance;
position = transform.position;
}
public void LateUpdate(){
// scrollwheel affect the desired ZOOM distance
desiredDistance -= Input.GetAxis("Mouse ScrollWheel") * Time.deltaTime * zoomRate * Mathf.Abs(desiredDistance);
//clamp the zoom min/max
desiredDistance = Mathf.Clamp(desiredDistance, minDistance, maxDistance);
// For smoothing of the zoom, optional
currentDistance = Mathf.Lerp(currentDistance, desiredDistance, Time.deltaTime * zoomDampening);
// calculate position based on the new currentDistance
position = target.position - (Vector3.forward * currentDistance);
transform.position = position;
}
in the ispector you can modify the zoom rate, min and in particular max :)
what type of this script is this, its not java script nor c#
Well your script is good but not enough. What I want is to zoom the camera but my camera remains still. When I apply your script, what it will do, it will zoom the camera but also move the camera from its position. I dont want that. I just want to zoom but not to move my camera from my still position. thnx