- Home /
Perspective Scroll Wheel Zoom freezes
I've managed to get the scroll wheel to zoom the camera in by changing the perspective, the problem I'm having is when it zooms in or out to the maximum distance I've allowed it freezes the scrolling zoom and I can't zoom in or out anymore.
if (Input.GetAxis("Mouse ScrollWheel") < 0) { if ((camera.fieldOfView > minZoom) && (camera.fieldOfView < maxZoom)) { camera.fieldOfView = camera.fieldOfView + zoomSpeed; } }
//This is for zooming out with the camera.
if (Input.GetAxis("Mouse ScrollWheel") > 0) {
if ((camera.fieldOfView > minZoom) && (camera.fieldOfView < maxZoom)) {
camera.fieldOfView = camera.fieldOfView - zoomSpeed;
}
}
I decided to go with a different method that works better for my game anyway, I hope if someone sees this and can answer it they do so just in case someone else has the same problem.
Answer by asafsitner · Dec 23, 2011 at 11:20 AM
As you're dealing with floats, it's probably a matter of precision. What happens if the perspective is greater than maxZoom? There's no way to get it back down. So instead of if statement, why not try using `Mathf.Clamp()` to keep the perspective in check?
Something like this maybe (c#):
camera.fieldOfView += Input.GetAxis("Mouse ScrollWheel");
camera.fieldOfView = Mathf.Clamp(camera.fieldOfView, minZoom, maxZoom);
Your answer
Follow this Question
Related Questions
How do I make the camera zoom in and out with the mouse wheel? 10 Answers
Zooming and scrolling into GUI 0 Answers
Character Zoom in and out 1 Answer
Setting pivot to the middle of two touches - 2D project 0 Answers
Tartan plaid flannel background in editor while scrolling through zoom levels 0 Answers