I have a deformed cube with a non-convex hull. I want to convert the deformed cube so its vertices lie in the same places but it has a convex hull.
I have MeshCollider attached to the deformed cube with Convex set to true and was hoping I could swap out the deformed cube’s Mesh with the mesh the MeshCollider uses for collisions- but Im having no luck.
I was hoping the MeshCollider’s Mesh was stored in the undocumented MeshCollider.mesh and so tried this:
var deformedMesh : Mesh = GetComponent(MeshFilter).mesh;
var collider : MeshCollider = GetComponent(MeshCollider);
var colliderMesh : Mesh = GetComponent(MeshCollider).mesh;
collider.convex = true; //set the MeshCollider up
collider.sharedMesh = null; //the deformed mesh gets re-deformed every now and then
collider.sharedMesh = deformedMesh;
deformedMesh = colliderMesh; //replace the cubes mesh with a convex version of itself?
//alsotried
deformedMesh.vertices = colliderMesh.vertices;
deformedMesh.triangles = colliderMesh.triangles;
deformedMesh.normals = colliderMesh.normals;
But it seems that the MeshColliders Mesh is not stored in MeshCollider.mesh as the above code does nothing- does anyone know of a way of accessing the mesh the MeshCollider uses for collisions?
Thanks