In my game, for my backgrounds I have separated visual meshes and a lower-poly collision mesh. The floor of the world is made up of mesh colliders. I have noticed problems with small collider+rigidbody objects falling through the floor. I have objects fall through as large as radius = 0.3, height = 0.6 (capsuleCollider), whether they are BoxColliders or CapsuleColliders. Objects are falling using normal physics gravity set at -9.81. Objects may only fall a distance of 1 meter before hitting the ground, so object speed is not very fast, yet then still tend to fall through.
My original floors were are all planar meshes of varying size. The testing meshCollider is about 85m X 50m (planar).
I tested a v-extruded version (about 4m thick) thinking that maybe having a thickness to the collider would help, but the results are exactly the same.
It doesn’t happen all the time and doesn’t seem to vary much with distance from world origin, so I can’t blame 32-bit float imprecision.
As far as I can tell, this does not happen with BoxColliders. I tested a box collider as a floor and NEVER saw an object fall through. However, I simply cannot use box colliders for my backgrounds and must make the mesh colliders work somehow.
I’m using Unity 2.6, but noticed that 3 added a Physics.collisionDetectionMode setting. However, the entry in the scripting reference states “Continuous Collision Detection is only supported for Rigidbodies with Sphere-, Capusle- or BoxColliders”. No mesh colliders.
Physics.minPenetrationForPenalty = 0.01
All items are built on realistic scale. Therefore a small item such as a gun, even with a somewhat oversized box collider, easily falls through the floor. Not every time mind you, but once in 20/30 times is enough to be unacceptable.
I’ve done some more testing and confirmed something very strange:
*** Colliders do not fall through when collision occurs entirely on a polygon face
*** Colliders FALL THROUGH when collision occurs touching a triangle edge between polygons
I don’t understand this at all. Why would a triangle edge cause a collision to fail?
My collision meshes are made of relatively large flat polygons. Any time a small object collision happens on the flat face of a polygon, it does not fall through. Anytime any part of the small collider touches a polygon edge, the collision fails and the object falls through the floor. This explains why the BoxCollider never failed because there are no polygon edges on the flat top face.
Here’s an image illustrating what’s going on.
Floor is a mesh collider.
The collider on the left will hit the flat triangle face and stop correctly.
The collider on the right hitting the triangle edge will pass through completely.
I’ve only tested box collider and capsule collider and both have this problem.
Surely with all the hundreds of thousands of users someone has run into this before…
Is there a way to change a forum post title? My original title isn’t really accurate. It should be something like: Mesh collider fails collisions on triangle edges
Have you tried setting the MeshCollider to be convex? I have heard that it’s more reliable, although dips in the floor would effectively be smoothed out.
Stick a BoxCollider under the mesh as a backup.
Also I think someone said MeshColliders have a maximum number of vertices in some situations.
not only more reliable, its required. Non convex mesh colliders are for scenery and must not move. They are not only extremely costly as their collision trees get moved around and force other surounding ones to be recalculated, they are additionally not able to handle collisions with other non-covex mesh colliders at all
But the answer here is simple: if the collision is already there when the simulation starts, it won’t enter the other body anymore, it will be in it. As such there is no ‘push out direction’ as it never entered it, hence the collision is ignored and it will fall through.
With box colliders this is not the case as each of the 6 sides is a math construct, not a mesh, as such it gets blindly pushed around.
Generally though, if you setup your level already with collisions happening before the physics even starts, you have to expect massive problems. at best they simply don’t register the collision, at worst you get distance / 0timedelta push outs that will accelerate them to thousands of units / frame and fire them away like a gauss cannon would have
I created a glacier in Blender that has a nice concave slope on it’s top side. The glacier is the gameobject that I have added the MeshCollider to. Since I want it to be concave in places, making the MeshCollider convex will mess things up.
The gameobjects that occassionally fall through the glacier are box or capsule colliders that are smaller than .1 units.
Adding a combination of box and capsule colliders to the glacier will probably work. I’d love to hear some other possible solutions too, since setting up multiple colliders in the glacier is probably going to be tedious and possibly not as smooth as I’d like.