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
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.