Skip to content
Advertisement

Javscript – Three.js Disable panning on mobile devices?

So I’m making a 3d project with three.js. Everything works as expected on my laptop. I’m using OrbitControls to allow camera movement, but i have disabled right click panning, because I want the camera just to rotate. When switching to a mobile device (iphone), using two fingers I’m able to move the camera (not rotate). Is there a way to disable this behaviour on mobile devices? My OrbitControls:

JavaScript

Update function:

JavaScript

Advertisement

Answer

It seems that you’re not disabling panning, but just changing the mouse action used by controls.

In order to disable/enable panning, you should use enablePan.

Now, you only want to disable panning in mobile, so we could pick a break-point for conditionally enable/disable panning:

JavaScript

Then, in your update loop, just invoke the above function:

JavaScript

You could approach this in several ways. For example: You could only execute this function once and not every frame.

Advertisement