three.jscontrols

How do I put limits on OrbitControl?


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?


Solution

  • 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;