- Home /
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! :)
Answer by 3dDude · Jun 26, 2010 at 03:16 PM
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! :)
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
Answer by ramp · Aug 28, 2014 at 06:00 AM
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
Answer by dttngan91 · Sep 03, 2014 at 09:47 AM
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?
Answer by astracat111 · Nov 07, 2016 at 07:42 AM
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;
Your answer
Follow this Question
Related Questions
Camera zooming in and out 1 Answer
Changing camera position to shoot through scope on gun 1 Answer
Raycast misses after camera zoom 2 Answers
Lining up Fov's 0 Answers