- Home /
Manipulating a vertex on a plane
How can I go about getting/translating a vertex of of a plane/cube?
I would appreciate some more information about what exactly you are trying to do with the information.
However, what you are likely going to want to do is get to the $$anonymous$$esh object that is available via the $$anonymous$$eshFilter component on your gameobject. Once you get the $$anonymous$$esh object, you can access the vertices, triangles, and uv arrays for the mesh and make modifications.
Answer by vik.vega · Jun 21, 2013 at 03:41 PM
you need to access the vertices through the Mesh function this way
function Update () {
var mesh : Mesh = GetComponent(MeshFilter).mesh;
var vertices : Vector3[] = mesh.vertices;
var normals : Vector3[] = mesh.normals;
for (var i = 0; i < vertices.Length; i++)
vertices[i].transform.position = vertices[i].transform.position + Vector3(0,(Random.Range(-1,1),0)
mesh.vertices = vertices;
}
when you have all your vertices into an array, you can manipulate them as you want.
beware, you may not know :
that there may be several vertices sharing the same position and their position is also stored in LocalSpace (that means their coordinates are relative to the object position)
Unity Documentation about the Mesh Class is here
This is right. One thing to add is that I think you need to recalc normals after modification if you want the mesh to look right.
Great, how can I identify the closest vertex based on a ray cast? Dist comparison based on impact point?
Your answer
![](https://koobas.hobune.stream/wayback/20220613104512im_/https://answers.unity.com/themes/thub/images/avi.jpg)