How to limit pan in OrbitControls for OrthographicCamera?

Hi There,

I currently working on an open project to create a station indoor map, but having difficulties to limit the pan when using orbitControls,

I tried to limit the control/camera position x/y/z but when i rotate the orbit all those coordinates suddenly changed, i know why this is happened but since i still confused. :upside_down_face:

The working example is here,

Any suggestion will be appreciated.


It’s best to modify OrbitControls for this use case. So copy the class and define two new variables that you can use to control the minimum and maximum pan movement at the top of the file.

var minPan = new THREE.Vector3( - 2, - 2, - 2 );
var maxPan = new THREE.Vector3( 2, 2, 2 );

In the update() method, add the following line after panOffset was added to the target of OrbitControls. minPan, maxPan );


Panning means to offset the control’s target vector and thus the camera. If you restrict the target vector, you also restrict the camera’s final position.


Oh my god, its working as well, still doesn’t believe it, adding only 3 lines of code just solve this problem… :clap::clap::clap:

Thank you so much!!


Thanks @Mugen87, I got asked by a client to add this yesterday. Gonna steal your solution :grin: