Camera Zoom problem (139853)

I am trying to make a RTS camera script that uses the Middle Mouse Button to zoom the direction the camera is pointing, but don’t know how to make it not scroll past a limit (to prevent clipping through the building models, or zooming out to far). So far i have:

    if(curDistanceCam > camDistanceMin && curDistanceCam < camDistanceMax) {
        		Camera.main.transform.Translate (Vector3.forward * scroll);
        		}

But don’t know how to allow the camera to scroll back once it reaches the limits (it locks up)

curDistanceCam is a Ray distance between the camera and the object directly in-front of it.

u wana zoom , like a sniper gun ? why u dont use zoom property in camera component ?

–

I meant to say Mouse Wheel, not button, using the wheel to zoom in and out

–

1 Answer

1

Use Camera.fieldOfView . Default is 60 , setting it at a lower value will zoom in.

how do i confine the field of view to a max and min, so they cannot zoom in or out too far?, since i am using the mouse wheel as a zoom in/out

–

Also, using the field of view for zoom would distort the perspective, wouldn't it?

–

Use Mathf.Clamp to clamp the max zoom , and it does distort the perspective.

–