Flattening a mesh based on hit.point

How do you flatten a mesh based on the point of impact or hit.point?

If you just need to edit the graphical representation, it is quite easy and not that much of a performance impact. You have the hitpoint, the mesh and the transform, so you can access the vertices like so:

hittransf = hitinfo.collider.transform;
tri = hitinfo.triangleIndex;
verts = hitmesh.vertices;
tris = hitmesh.triangles;
thevertex = hittransf.TransformPoint(verts[tris[tri*3]]);

and to modify the vertex you do:

verts[tris[tri*3+thevertex]] += Vector3.up * ammount;

I just snipped this out of a project, so please take into account that some of the variables above are already set. For example, you need to grab the mesh (hitmesh aboive) and after the operation you need to set the vertices of the mesh to the edited array (verts).

This should get you started. Hope it helps! :slight_smile: