How to constrain the camera not to move on the Y axis?

Hello, I would like to prevent the rotation of the camera on the vertical axis.

I had found a solution with the FreeMouse custom but not to use the classic system, but with the custom camera it works badly on firefox and safari →
(when you turn, the movement stops for no reason in safari and firefox).

So I used the classic freecamera system, but I don’t know how to block my axis …

Hey @LeoPaulD,

The easiest way that I could think of to restrict the camera horizontal rotation would be to ensure that the FreeCamera’s rotation around the x-axis is always zero. This can be accomplished by putting in code to change camera.cameraRotation.x in a manner like this:

scene.onPointerObservable.add((eventData) => {
    // This will block out vertical rotation
    // For blocking out horizontal rotation, simply use y instead of x
    camera.cameraRotation.x = 0;

Now this code will make it so that any mouse movement will zero out vertical rotation but you’ll need to add additional code if you want to be able to turn off this functionality temporarily. As far as why the custom code isn’t working properly for Firefox and Safari, I’d have to dig into that but I suspect that it’s hitting some kind of logic barrier.

1 Like