ArcRotateCamera is sliding on collisions

Hi,

I’m trying to set up collisions to the ArcRotateCamera so the user can’t move it through some meshes, but I’m facing an issue, as the camera slides forward when it collides with the floor and the user continues dragging the rotation in the viewport (changing the “beta” of the camera). If the camera.target.y value is closed to where the ground plane is, the issue is less noticeable.

Here you have a playground:

Is it possible to configure the camera such as when it collides with a mesh it doesn’t slide forward/backward and just stays at its last position before the collision? I’ve tried with different collisionRadius values, but it doesn’t seem to help much.

Thanks

cc @PolygonalSun

AFAIK, there is no way to modify the collisions so that it doesn’t slide when moved (I think that logic is handled by the CollisionCoordinator class possibly?). Something that you could do that might work is to set the camera.upperBetaLimit and when it hits a certain beta, you would just stop and there would be no sliding (I think that the limit for the given PG would be somewhere around 1.62 for a limit). For differences to the target’s elevation, you may need to recalculate this but this limit might provide the desired effect.

1 Like

Anyway, it works. o( ̄▽ ̄)o
See line 33.

4 Likes

Thanks for your suggestion and sharing your code! It’s a nice approach, but it somehow makes the camera to jump a bit when colliding and makes it stuck also in the “alpha”, so the movement when collided is not smooth if the user tries to rotate the camera sideways.

I’m going to look further into the method you posted and trying to write some logic that involves checking when the camera has collided and the new position calculated by that.

Regards