Mouse drag direction with non-default camera upVector

Hello everybody,

this is my first time posting a question here and I have quite a limited experience with babylon.js, so I am sorry if this had been answered before, or if it is really trivial. However, I have done my search, and I could only find this one similar thread, which unfortunatelly had no answer: Using Universal Camera in scene with Z-up axis

My question is about fixing mouse drag direction when I change UniversalCamera’s upVector. Say I want to toggle between a setting where the upVector is the default value (0, 1, 0) and another setting where the upVector is opposite to the direction of gravity of a spehrical body (say the upVector is (1, 0, 0) when camera is 90° to the east). It mostly seems to work fine by just setting the upVector property, even the movement direction. However, dragging the mouse rotates the camera around incorrect vectors and it does not behave as expected at all. In this PG: you can see that by dragging the mouse up, the camera turns to the right instead of up (the camera movement actually forms an arc, so it’s not just about swapping directions).

Is this a bug or am I missing some simple fix?

For the record, I am using an OriginCamera as described here: Floating Origin (Huge Scenes Support) | Babylon.js Documentation, but I was able to reproduce the issue even with the standard UniversalCamera, as seen in the playground.

Thank you very much for an answer!

Hello and welcome to the Babylon.js forum!

One way to do this is to parent the camera to a transform node and rotate the transform node instead of changing the camera’s up vector.

Example playground

I don’t know if it’s the best way to do it, but it works.