Bug in mesh/capsule collision

Hi, I’ve found a bug with capsule collider against a terrain mesh.
Try https://playcanvas.com/editor/scene/1281938
Start it and observe the capsule moving forward.
When it reaches the slightly darker triangle it falls through in a buggy way.
This is not the only case, but the one I chose to isolate from a larger terrain.
I’ve not found any settings on the capsule or terrain colliders that have to do with the bug
It seems like some triangles are just not good for capsule collision.
Sphere collision works fine.
Reading [BUG] Terrain Collision Meshes - #7 by devMidgard I’ve inspected my terrain mesh, but can’t find anything wrong with it. I’ve added both obj and fbx versions.

Hi @Snupty,

That basically is an issue with Ammo.js and how it handles collisions with large triangles. It’s a known issue as you’ve found out.

One thing you can try and see if it fixes it for you is to enable CCD, check this sample:

Though sometimes even that won’t work, on a game I’ve worked on we had to manually upgrade to a beta build of Ammo3 (Bullet v3.0) to fix terrain collisions with capsules. From this repository:

Feel free to submit this issue on the PlayCanvas engine repo as well.

1 Like

Thanks, I will try that!

Another alternative that may work, is to create a compound collider with a box and two spheres that mimics the shape of the capsule.

It won’t be a perfect match but depending the type of your gameplay it may work as well.

I get errors when trying to use ammo from the repo you point to:

Using compound could be an option, but we also have a trigger collider in the subtree, not sure if that mixes well. Also, having more colliders means they might resolve in opposite directions and get you stuck. But will try it.

Oops, some of that was forgetting to set the references on ammo.wasm.wasm, but still get an error

Alright, there was also a name setting. It runs now, but fails in the same way on the same triangle, alas

1 Like

A compound collider spawns a single body in the physics sim. But yes it’s not ideal, it may create edges that potentially can get you stuck.

Make sure to use the files from the PR I’ve linked above, not from the repository master branch.

I believe I did use the files from that PR. Using compond collision with two spheres for now, seems to work. Thanks a lot for your help!

1 Like