Issue involving ArcRotateCamera collisions and angular limits

I’ve encountered an issue when using an ArcRotateCamera with both angular limits and collisions enabled. Here is a playground which reproduces the issue:

The issue is that when the collision handler calls setPosition on the camera, the spherical coordinates are recalculated from the new position, and the resulting alpha coordinate is in the range [0, 2*Pi), which may be outside the current alpha limits, which will clamp the alpha value to the limit. This causes the camera to move unexpectedly to one of the limits.

I see two ways of avoiding this behaviour:

  1. Set the new alpha value to the rotation closest to the old value by adding 2 * N * Pi, with appropriate N.
  2. When we rebuild the angles, update the angle limits so that they are effectively the same. (Also by adding 2 * N * Pi).

Some questions:

  1. Do you think this issue is worth fixing? If so, I can submit a PR.
  2. Do you see any alternative way of fixing the issue?
  3. Is there any way of avoiding this issue in the current version of Babylon?


1 Like

Hello and welcome!

if you can submit the PR today I can make it part of the upcoming 4.2

I’ve submitted a PR.

Thanks for the quick response. FYI I’m in CET time, so I’ll be available to fix issues for a couple of hours before I need to sleep :slight_smile:
1 Like

and I merged it

thanks a lot!

1 Like