How do I put limits on OrbitControl?

user1659565 picture user1659565 · Apr 5, 2013 · Viewed 21.3k times · Source

Is there a way to put limits on the OrbitControls.js? Imagine I'm creating something above the ground, I wouldn't like the camera to go below the ground, know what I mean?! The same things goes for zoom in and zoom out. Is there a way to set some variables to limit that because I don't want the camera getting to close or too far away?

Answer

uhura picture uhura · Apr 5, 2013

OrbitControls source

Zoom in / zoom out

this.minDistance = 0;
this.maxDistance = Infinity;

Where to stop rotation :

this.minPolarAngle = 0; // radians
this.maxPolarAngle = Math.PI; // radians

Don't let to go below the ground

controls.maxPolarAngle = Math.PI/2;