How to detect collision between a camera and an object?

I want to know how to implement collision detection between a free camera and a mesh in Babylon.js. For instance, if I have a scene with a ground, a free camera, and a box (all of them detecting collisions and gravity), how would I write my code to perform certain actions, like printing ‘Hello’, when the free camera collides with the box?

For example, I can use the following code to detect collision between two meshes, but is there a way to do this between a camera and a mesh, or between two cameras?


scene.registerBeforeRender(function () {
if (mesh1.intersectsMesh(mesh2, false)) {

    } else {
        
    }

}

FreeCamera | Babylon.js Documentation (babylonjs.com)
FreeCamera | Babylon.js Documentation (babylonjs.com)
FreeCamera | Babylon.js Documentation (babylonjs.com)
This turns on collisions between cameras and objects, but it is not clear if collisions occur between cameras.

1 Like

do u give me a demo? thanks!

why doesn’t copyFrom before intersectMesh work | Babylon.js Playground (babylonjs.com)
Cameras cannot collide with each other, and you can create a corresponding ellipsoid mesh to replace collision between cameras.

1 Like