How to change UniversalCamera behaviour

Hi there,
I’d like to use the UniversalCamera like it was an ArcRotateCamera but without setting the target :slight_smile:
So when i click the right mouse button i’d like to make panning. the default is rotation (both for left or right click). Is it possible to change this feature using onPointerObservable and then do some job?

Second question: i’ve activated also the zoom-in with mouse wheel (camera.inputs.addMouseWheel();) but it’s too fast. Is there a way to reduce the speed?

This is my PG (is a little bit messed up): https://playground.babylonjs.com/#A6TFXB#10

Thank you in advance

Adding @PolygonalSun for this one :slight_smile:

I don’t know for the first part, but for the second part you can use wheelPrecisionX/Y/Z from camera.inputs.attached.mousewheel:

4 Likes

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

Thank you @PolygonalSun, i understand how it works.
Maybe i’ve to change something because after some move the cams goes far away.