- Home /
Orbit Camera Zoom limit
I was trying to do a zoom on a orbit camera script using touch. Pan to rotate the camera, pinch to zoom by follow an object. the problem is I unable to set the correct zoom limit, because the zoom axis might be y, or z depend on what my current camera angle is due to the orbit position. And the zoom I using the Transform.Translate after I get the pinch distance. What is the correct way to set zoom limit on Translate function when under the orbit camera?
the code I paste into a pastebin, and this code has no zoom limit. http://pastebin.com/y8vUKJ5Y.
thank you.
Answer by giudark · Jan 27, 2014 at 02:17 PM
if I understand what you mean you have to use the clamp first. In particular, you could take an approach like this:
desiredZoom += Mathf.Clamp(lastDist - currDist, -30.0f, 30.0f) * Time.deltaTime * zoomFactor;
desiredZoom = Mathf.Clamp(desiredZoom , minPossibleZoom, maxPossibleZoom);
/* For smoothing of the zoom */
currentZoom = Mathf.Lerp(currentZoom , desiredZoom , Time.deltaTime * zoomSpeed);
/* calculate new position based on the new currentZoom */
position = (rotation * Vector3.forward * currentZoom);
player.transform.position = position;
for further methods of managing the camera you can look at this link, the code that I wrote is a modified of MouseOrbitZoom