x


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?

more ▼

asked Feb 07 '12 at 06:12 PM

tonydemot gravatar image

tonydemot
45 12 16 19

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.

Feb 07 '12 at 06:13 PM Meltdown

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).

Feb 07 '12 at 06:23 PM asafsitner

can you dolly via script or would this be an animation ?

Feb 07 '12 at 06:58 PM tonydemot

i will probably make the zooming via scroll wheel that changes the field of view

Feb 07 '12 at 10:22 PM tonydemot

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("Mouse ScrollWheel") * _zoomStep;

Or possibly with Lerp to smooth the zooming:

_myCamera.fov = Mathf.Lerp(_myCamera.fov, _myCamera.fov + (Input.GetAxis("Mouse ScrollWheel") * _zoomStep), Time.deltaTime * _zoomSpeed);

Might want to add a Mathf.Clamp() call to limit zoom range.

Feb 07 '12 at 10:48 PM asafsitner
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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?

more ▼

answered Feb 08 '12 at 05:43 PM

tonydemot gravatar image

tonydemot
45 12 16 19

would this work?

Feb 08 '12 at 06:10 PM tonydemot
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3314
x981
x76
x62
x56

asked: Feb 07 '12 at 06:12 PM

Seen: 1185 times

Last Updated: Feb 08 '12 at 06:10 PM