rapier
rapier copied to clipboard
Triangle Collider Broken, but instead using Convex Hull is Perfectly Fine
I was using lyon to make triangles from collider info obtained from svg shapes. However, when testing, I've found that when using the Triangle shape, the collision is very wacky and penetration happened a lot. And then I switched to using Convex Hulls, and all my issues disappeared.
May there be an error with Triangle collision, or should it simply be discarded/redirected to convex hulls?
Triangle meshes don't tend to work very well for collisions because there isn't a way to calculate when a vertex is inside the mesh. Because there is no concept of inside or outside the mesh, if something passes through the wall, the physics simulation cannot push the object out of the mesh, which makes penetrations much more common. In other words, meshes are hollow.
Convex hulls on the other hand, because they are convex, do have the concept of an interior and an exterior, which solves the penetration calculation issue.
You can read more in the docs here.
The issue here seems to be discussing 2D, in which case triangles do have a well defined interior.
I have observed a case with bevy_rapier2d
where I can hit a fixed Collider::trimesh
(or same-shape Collider::compound
made of either Collider::convex_polyline
or Collider::convex_hull
triangles) and if I hit it at the seam of two triangles, I get significant penetration and even tunneling "through the seam". This happens even with Ccd::enabled()
on all the bodies.
As I said, using Collider::convex_hull
didn't fix my issue, as long as I hit a seam between the 2D triangles.
(I didn't report this independently yet because I'm still struggling with the basics of my scene, hopefully I can extract the behavior into something simpler if this isn't obvious.)
Here's what my triangles look like, the problematic seam is the one going straight through the ring. (The other seam might be buggy too, but at least it doesn't trigger as easily.)
Potential other reports similar to what I'm experiencing, "passing through the seams":
- https://github.com/dimforge/rapier/issues/182
- https://github.com/dimforge/rapier/issues/165