Disable a pan axis in OrbitControls

Hi everybody,

I’m wondering if it is possible to limit the OrbitControls panning feature to just one axis, for example only allowing the user to pan in the y axis but not x.

The documentation says its possible to disable a single axis when rotating but unfortunately nothing about my case.

Greetings,
Alexander

Hey,

Well you could lock the camera and the orbit.target when panning.
Like this:

orbit.addEventListener( 'change', function(){
   //...
   this.target.y = 0;
   camera.position.y = 0;
   //...
}

This will keep the view fixed on Y. Only left and right pan is possible.
But you may want to do this only when panning, not when orbiting.

2 Likes

I’d rather like to limit it to only the y axis, so only left and right is possible. :smiley:

haha sorry. updated my post…

Thank you very much it does work! Do you maybe know as well how I can limit the panning distance? :smiley:

For example I only want to allow panning in either direction for a little bit.

This heavily depends on the use case… For a very basic and simple example, something like this does the trick:

orbit.addEventListener( 'change', function(){
    if (this.target.x < -1){
        this.target.x = -1;
        camera.position.x = -1;
    } else if (this.target.x > 1){
        this.target.x = 1;
        camera.position.x = 1;
    }
})

1 Like