How to change UniversalCamera behaviour

Hey @Mercurio, using @Evgeni_Popov’s code, I added some code to do a rudimentary pan:
3D button | Babylon.js Playground

The basic idea is, if you don’t want the default rotation behavior, you’ll have to remove the default mouse input behaviors and add your own. You can absolutely use onPointerObservable. In the provided link, I used camera.inputs.removeMouse();(Line 17) to remove the default behaviors. Next, you’ll want to check out Lines 98-120.

When a POINTERDOWN is detected, a pointer lock will be enabled on the engine. This means that your mouse cursor will not actually be moving but will still provide deltas of change (movementX and movementY).

For POINTERMOVE events, if there’s been a pointer lock placed on your cursor, we take that delta data and change the position of the camera. Note that if you incorporate any type of rotation, you will have to translate the relative movement of the cursor to the global movement of the camera.

Finally, when the button is released (POINTERUP), we release the lock and the cursor is free to do stuff.

5 Likes