- Home /
Convex Mesh Collider on Procedurally generated mesh does not conform..
I want to have 2D, planar, convex polygons (like paper) in a 3D space. I also want them to be rigidbodies with colliders. I have a Mesh Collider
on them, and after they have had their mesh generated, I do GetComponent().sharedMesh = mesh
. The problem I have is that if the Mesh Collider
is not set to convex, I get an error saying Unity 5 doesn't support non-convex collisions anymore. I know all my polygons will be convex, so I set GetComponent().convex = true
. However, when I do this, instead of using the sharedMesh
, Unity places a crude bounding box around the polygon and uses that as the collider (see the green box around the polygon in the image).
I can't use this because the bounding box encloses too much empty space, so the mesh would "collide" even though it's no where near actually colliding.
Before I go writing my own collision detection system, I want to know if Unity can do this properly. I've looked at the Quad
and Plane
objects. Those are 2D planer convex polygons, and they have properly fitted colliders, so you would think Unity could do properly fitted colliders on other 2D shapes (besides rectangles) out of the box. But how? I tried procedurally generating a plane, applying a mesh collider with the convex box ticked, and it still gave me a collider that was bigger than the actual mesh.
Any solution Croolsby? I am facing the same problem at the moment =(
Answer by nickeeromo · May 29, 2015 at 09:17 AM
I know I won't be much help, but I had a similar situation, only with using a quad. For your shape, if it is 2D, a mesh collider simply won't work properly FOR SOME REASON unbeknownst to me. Every place I look, they tell me to use a box collider, but that is just for a normal 2D shape like a quad. Now, if your shape is not a plane or quad but still 2D, don't know enough on my own to help you, but these may help:
A reference: http://forum.unity3d.com/threads/why-is-mesh-collider-so-large.152254/
Little outdated but may still be helpful: http://answers.unity3d.com/questions/330315/scaleing-the-mesh-collider-1.html
If nothing else you might consider using a compound collider to approximate the shape. More on that here: http://docs.unity3d.com/Manual/class-BoxCollider.html