- Home /
Glitchy Convex Mesh Collider
I have an object shaped like an isosceles triangle:
When my engine moves it around by manually setting its position, it needs to collide with other objects as a trigger, most of which are simple box colliders with kinematic rigidbodies. I've given it a mesh collider, which without being marked as convex, works perfectly in colliding with everything except other triangles, since non-convex mesh colliders don't detect each other.
When I try marking it as convex and moving the triangle perpendicular to its width, it gets really buggy passing through a normal box-collider object, still thinking it's colliding well after it's passed through to the other side by a good 10 units or so. Other objects moving into the triangle work fine. The mesh has 208 triangles, within the 255-triangle limit imposed on convex mesh colliders, and I've tried setting its rigidbody's collision detection to continuous/continuous dynamic to no avail.
Creating umpteen child objects with long, rotated box colliders to fit the shape and fill in the end corners complicates my code just for this one case, introducing yet other bugs, but that's what I've ended up having to do.
I'm curious - are convex mesh colliders this buggy for everyone?
Edit: I've created a minimized sample project showcasing the issue; download it here.
Move the 3 triangles with the scroll bar at the bottom through the 3 boxes slowly, and notice the difference between the triangle with the convex mesh collider (on the left), the one with the non-convex mesh collider (center) and that of the box collider (right). Two of these things are kind-of the same; can you guess which one of these doesn't belong?
Looks like a submittable bug, no?
I haven't experienced this kind of problem before- how complex is the mesh? Does it have any exposed backfaces?
$$anonymous$$eep in $$anonymous$$d that a convex meshcollider just consists of the convex hull of the whole object. It seems your triangle have a hole in the center, this won't exist in the collider. Convex means there is not even a small bump in the colliders surface. All suface angles are greater than 180°.
The next thing is you should attach the rigidbody to the moving objects. You don't need to use gravity / forces, just make it a kinematic rigidbody.
Btw. when you select your object you should see the generated meshcollider in the sceneview.
The mesh is the shape in the picture above, with 208 triangles and no back faces that I know of. I just created a demo project showcasing it in my post above; see for yourself.
Yes, this shouldn't happen ;) This is clearly a bug in the convex meshcollider. The needed distance to exit the collision is about the length of the object, but in the wrong direction ;) It's like the bounding box is a perfect cube.
I would definitely submit a bug report. You should explain exactly what is wrong and how to achieve the result. Your test scene is perfect.
Btw, it seems when you move the cube a little bit (maybe the $$anonymous$$-penetration-distance?!) while the collision is "stuck", the collision ends.
edit Just tested the other 3 directions and it's the same result. It really looks like a bounding cube
Answer by blitzen · May 23, 2012 at 08:09 PM
Submitted.
Good call regarding the bounding box, Bunny83. That's why it works fine moving side to side in the direction of its acute corners, but not forward/backward or up and down. Thus since it only happens when you pass all the way through to the other side, something's faulty in triggering OnTriggerExit() beyond checking its Collider.bounds.extents.
It also only seems to happen for small, narrow collision obstacles; if you scale the little rectangle up to about (5,5,5), it then works OK.
There's a good several days of my life for ya.
They considered it a manifestation of another "known bug" in 3.5.2, yet two months later it still appears when you run the above example program in 3.5.4.
I wonder when they plan on tackling it, and it also brings into question just how many other known bugs they leave in the program each update.
Their latest response is that it's slated for 4.0 and not any time in 3.5, so that answers the question of their policy on these things. One would only hope they don't leave any known bugs in major version releases.
Whelp, running the example project above in 4.3, it looks like the bug is still there a year and a half later.
Good hustle, guys.
I'm running the latest version 4.5 and this still seems to happen. Have you figured out a work around? I was thinking of creating several "planes" and hiding these within my object then giving them convex colliders but after reading this I'm not sure it will work. What are your thoughts?
That's what it seems you'll end up having to do. Resorting to such increased the complexity of my engine several fold, and to this day, this has kept the relevant aspect of my project stagnant.
I wonder just how many of these known bugs they decide to just leave throughout several major releases.