Setting up a valid range for the camera rotation

Hi all,
The current documentation has this nice demo code customizing camera controls for keyboard and mouse. For convenience, the original PG code is this:

I modified this example to further customize it in a way that the range of the camera tilt (rotation.x) is not the full +90/-90 but a smaller range. The idea is to prevent the camera looking at the top or bottom, where the viewer can lose reference. I do it by checking the X rotation property of the camera and only modify the camerarotation if the values are wihin a range; however in the PG (see line 309) :

rotation in the x axis does not happen. In my hmtl version (non PG) the issue is slightly different and the rotation limit is somehow bypassed, before the camera gets stuck outside the “allowed range”

Helps or hints are welcome,
luis

Hello and welcome to the Babylon community!
Have you tried logging in the values on the console to check if they are in your expected range?

1 Like

Yes, in the local browser I did exactly what you mention. That’s how I could see that there are rotation actions that are not controlled by the javascript loop. I can monitor that I do not actively rotate the camera beyond the limit, however the camera goes beyond the threshold anyway. It is like some rotation happens without my control.

That might be your inertia Camera | Babylon.js Documentation (babylonjs.com)

Thanks again but … nope. As I understand it the inertia controls how the camera moves after you release the mouse click. The issue is that it gets rotated (with an inertial motion or not) by some background code that I do not control. To be more clear, lets suppose that I set a max X rotation of 0.1

  • Current rotation = 0
  • I execute a rotation of 0.02 as a result of a mouse action
  • current rotation = 0.02
  • I execute a rotation of 0.05
  • Current rotation = 0.07
  • I do not execute a rotation of 0.08
  • Current rotation = 0.07
  • Current rotation = 0.2 (!!!)

(I set the inertia = 0 but did not change the issue).

And this only happens on the HTML version, not the playground, is that correct? I’ll add @PolygonalSun to this conversation as he might have a better idea of what’s going on.

Exactly. In the PG, there’s no rotation at all. Thanks for your help