Capsule floating above ground when using moveWithCollisions and gravity in Babylon.js

Hi everyone, I’m new to Babylon.js and have been stuck on an issue for quite some time. I’d really appreciate any guidance you can offer.

What I’m trying to achieve is fairly straightforward: I have a capsule that should be able to move freely along the ground, with its movement properly blocked by obstacles. From the API documentation, AbstractMesh.moveWithCollisions seems like a great fit for handling this.

In my test setup, I’m continuously applying gravity to the capsule. My expectation is that it should stay grounded and closely follow the surface. However, I’m noticing that it consistently floats a small distance above the ground instead.

I’m not quite sure what might be causing this behavior. Has anyone encountered something similar or knows what I might be missing? Any suggestions would be greatly appreciated!

pg test

Hey there and welcome!

This is because you need to define the surrounding ellipsoid:

Babylon.js Playground - #UBETQ2#1

capsule.ellipsoid = new BABYLON.Vector3(0.3, 0.7, 0.3);
capsule.ellipsoidOffset = BABYLON.Vector3.Zero();

Yes, I can see the effect, but I have a question: if I rotate the capsule 90 degrees along the Z axis, it still floats in the air, as if the capsule has some kind of outer bounding sphere around it.

You will always to have to update the ellipsoid to fit. The ellipsoid is not automatically updated