Camera Zoom in Script....

Can someone tell me how to do a camera zoom-in script? So my view will start zoomed out then it will zoom in and stay that way just to give some view of the surroundings...

Thanks a bunch! :)

4 Answers

4

well i don't know what controls that you want but if you want to zoom in you can change the cameras field of view (E,G)

var zoom : int = 20;
var normal : int = 60;
var smooth : float = 5;
private var isZoomed = false;
function Update () {
     if(Input.GetKeyDown("z")){
          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);
     }
}

Edit added smooth speed to the movement.

hope this helps! :)

Could you tell me how to add speed to the camera?

–

made a edit :)

–

How about without input? Could you tell me how to zoom in from the very beginning?

–

well if you wanted to start with it zoomed just make var isZoomed = false; and make it var isZoomed = true; but if you wanted to always be zoomed i think you can change the camera.fieldOfView if you select the camera and just change the value in the inspector

–

No estoy muy seguro de lo que quieres decir ... Tambin habla usted Ingls? Tengo que usar traductor Google para escribir esto.

–

HI,
Create a java script MonoDev and put those codes after that attached to Main Camera in Hierarchy Layout.Camera Projection to be perspective only.

Thanks
Ram

There are two ways to implement zoom method. One is changing the field of view of camera and the other is changing z position of camera. Which way is better?

Using Unity3D’s camera controll free look script, you can place this in it’s Update() method:

float mouseScrollSpeed = 5f;
m_OriginalDist -= Input.GetAxisRaw("Mouse ScrollWheel") * mouseScrollSpeed;