How to limit movement of camera by some geometry?

Hi all,

Pls could someone help me to figure out how to limit movement of camera by some geometry (for example box)

Here the sample of camera behavior that I want to create

thanks all for attnetion,

Kind reegards.

1 Like

To do that, you can enable collision for your camera and your box.
Read the doc : Cameras, Mesh Collisions and Gravity - Babylon.js Documentation


this sample don`t work

Hi Ivan! Here’s a better/fresher demo (and thx for the broken link report):

Only for free-cams, of course. This built-into-BJS collision system is designed-for camera-to-object free-cam FPS-shooter games, and similar uses.

The camera.ellipsoid collider can be set to any dimensions, and there is also a camera.ellipsoidOffset which “shifts” the position of the camera’s ellipsoid collider, if wanted.

There is also a static property… engine.CollisionsEpsilon (BABYLON.Engine.CollisionsEpsilon) that affects the “scrub-off” and “climb-over” angles/characteristics. We can talk more about scrub-off and climb-over stuff, later, if ya want.

Generally, avoid colliding with low-height obstacles, for now. Or maybe use obstacle.ellipsoidOffset.y to raise the collision ellipsoid on low-height obstacles.

What happens: camera tries to climb-over low-height obstacles (dependent upon engine.CollisionsEpsilon setting)… but camera keeps being pulled back to floor… due to gravity. This makes freecam “jitter” when continued up-arrow PUSHING the camera… against a low-height obstacle.

I hope this helps. Got questions? Just holler.

Yep, it works, now I need to insert geometry that I created in some 3D program, and I need this geometry to limit the camera, do you have some similar samples?

To import geometry I encourage you to use Exporters from blender, 3dsmax or Maya or anything capable of generating .gltf file format:

Then you can easily flag any mesh as collidable like in @Wingnut sample

Funny situation, when Im importing mesh to scene, it doesn`t limit my camera and this camera falling down…

Did you make sure to flag them as checkCollisions = true;

And beware: make sure to flag the right mesh (as you may have a hierarchy of meshes)


I have box check collisions,


Maybe I need to write mesh.checkCollisions=true ???

Well with just a screenshot it is like trying with a crystal ball:)

Can you repro in the playground?

I hope it will be better


and that does not work? So weird. Please create a repro in the playground

It works, for box it works, but for mesh not, and I`m trying to figure out how to do that,

And sorry: what does it mean “repro in the playground”?

try to recreate the issue here:
A doc about how to reference external assets: Babylon.js Documentation

I inserted my code, and saved by the name of current topic, is it enough for you?

nope:) I do need it in the playground to be able to easily modify it

I copied everything here, what to do to send it to you?

Click the Save button on top and copy the browser URL and reply with the URL.

1 Like

I hope thats it…

This seems to work? What is not working on this playground?