Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Create a vertex in a specific point of a plane

Discussion in 'Scripting' started by game4tress, Jun 3, 2015.

  1. game4tress

    game4tress

    Joined:
    May 13, 2010
    Posts:
    46
    I have a plane and I want that when a sphere touches a certain place in the plane, for that place (vertex) to move to a certain location in order to deform the plane.
    I know the code to deform the plane by accessing its vertexes (code I list bellow), but I need to create a new vertex in a specific position. Is this possible? How?

    My thanks in Advanced

    Code (csharp):
    1.  
    2. Mesh mesh = new Mesh ();
    3. mesh.Clear ();
    4. mesh = mainObject.GetComponent<MeshFilter> ().mesh;
    5. Vector3[] vertices=mesh.vertices ;
    6. float fl = 0.2f;
    7. vertices[41]=new  Vector3(vertices[41].x+fl, vertices[41].y, vertices[41].z);
    8. mesh.vertices=vertices;
    9. mesh.RecalculateNormals();
    10.  
     
  2. game4tress

    game4tress

    Joined:
    May 13, 2010
    Posts:
    46
    I'm trying something like the code I post bellow in order to select the vertex, but after using linq I'm not able to determine the index position of the selected vertex (this is, if the code really works besides that, because I don't know if it's doable)

    Code (csharp):
    1.  
    2.         Mesh mesh = new Mesh ();
    3.        
    4.         Debug.Log ("MESHTEST Ceph Point");
    5.        
    6.         mesh.Clear ();
    7.        
    8.         mesh = mainObject.GetComponent<MeshFilter> ().mesh;
    9.        
    10.         Vector3[] vertices=mesh.vertices ;
    11.        
    12.         var V3=(from cur in vertices
    13.                where (cur.x==ponto.PontoX) && (cur.y==ponto.PontoY)
    14.                select cur).FirstOrDefault();
    15.