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! :)
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! :)
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! :)
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;