- Home /
Question by
JasonAnx · Jan 08, 2016 at 08:39 AM ·
collisioncollidersmesh manipulation
Is it possible to set the shared mesh of a collider to just the first set of indices of the mesh (through code) ?
Hello!,
In my code, I have something like this
mesh.subMeshCount = 2;
mesh.vertices = SomeVertsArray;
var solidBlocksTris = SomeTrisArray;
var lquidBlocksTris = AntrTrisArray;
mesh.SetIndices(solidBlocksTris, MeshTopology.Triangles, 0);
mesh.SetIndices(lquidBlocksTris, MeshTopology.Triangles, 1);
mesh.Optimize();
mesh.RecalculateBounds();
mesh.RecalculateNormals();
filter.mesh = mesh;
filter.mesh.uv = someUvArray;
// Mesh m = new Mesh();
// m.vertices = SomeVertsArray; // more verts than needed
// m.triangles = solidBlocksTris;
// collider.sharedMesh = m;
collider.sharedMesh = mesh;
the thing is that, setting sharedMesh = mesh for the collider uses both the first and second set of indices for collision, but I'm using the second set of indices as water, and it should have no collider.
Is there any way to set the shared mesh of a collider to just the first set of indices of the mesh?
or
Using the commented part of code does work, but I don't know the performance impact that using another Mesh could have in contrast with using the same as the filter.
Any help would be greatly appreciated : )
Comment
you could use two mesh filters. split the submeshes up, use one on filter and collider and the second on filter. I don't think it's possible to assign submeshes as colliders.