- Home /
Making the camera zoom in and out?
how would you make a camera that zooms in and out im making a strategy game and i need the camera to zoom in and out how would you do this in script?
People aren't going to write scripts for you. Do some tutorials and use the search feature in the top right. Your questions have been asked many times before.
Essentially, change the camera's Field of View.
An alternate method, actually moving the camera closer or farther to get the desired effect is actually called 'Dolly' and is something else entirely (it is in fact the instrument on which cameramen in film and television use to move the camera around).
can you dolly via script or would this be an animation ?
i will probably make the zoo$$anonymous$$g via scroll wheel that changes the field of view
Dolly is actually moving the camera, for instance with an animation. Or with a Translate()
method call. This is used mostly for cut-scenes and not, say, for sniper rifle scopes, which is usually done with FOV change.
A simple line of code should be able to handle it for you:
_myCamera.fov += Input.GetAxis("$$anonymous$$ouse ScrollWheel") * _zoomStep;
Or possibly with Lerp to smooth the zoo$$anonymous$$g:
_myCamera.fov = $$anonymous$$athf.Lerp(_myCamera.fov, _myCamera.fov + (Input.GetAxis("$$anonymous$$ouse ScrollWheel") * _zoomStep), Time.deltaTime * _zoomSpeed);
$$anonymous$$ight want to add a $$anonymous$$athf.Clamp()
call to limit zoom range.
Answer by tonydemot · Feb 08, 2012 at 05:43 PM
So far iv got public var fov = 60; public var fovmax = 90; public var min =30; function Update(){ if (Input.GetAxis("Mouse ScrollWheel")> 0){ Camera.main.fieldOfView = fov--; } if (Input.GetAxis("Mouse ScrollWheel")< 0){ Camera.main.fieldOfView = fov++; } }
im going to delete fovmax and min and replace with zoom speed also maybe distance?