- Home /
Camera Zoom problem
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 $$anonymous$$ouse Wheel, not button, using the wheel to zoom in and out
Answer by Crystalline · May 31, 2015 at 09:45 AM
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 $$anonymous$$, 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 $$anonymous$$athf.Clamp to clamp the max zoom , and it does distort the perspective.
Your answer
![](https://koobas.hobune.stream/wayback/20220613200439im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
RTS Camera Zoom w/ Rotation 0 Answers
RTS Style Camera Scrolling 8 Answers
Unity3d RTS style camera movement is jittery 0 Answers
Camera zooming in and out 1 Answer
Changing camera position to shoot through scope on gun 1 Answer