Camera Passing through GLB Objects

Hello,
i have a scene in which i have different GLB objects like 100-120 objects. Currently my camera is passing through the scene objects. how I can stop my camera to pass through the objects?

1 Like

There are many approaches, all with different trade-offs and consequences.

The easiest is to limit the height of the camera.
Before you call controls.update do something like…

let camCeiling = 5;
camera.position.y = Math.max( camCeiling, camera.position.y);

Next, is doing a raycast from the controls.target to the camera.position, and moving the camera to any intersection point. The downside of this is that raycasting can be very slow with really complex scenes.
Next is using a library like mesh-bvh to pre-process the scene and accelerate the raycasts…
The downside of this, is that the bvh has to be rebuild when the scene changes… but for mostly static scenes, this might not be too bad…

1 Like