- Home /
 
Mesh Vertex
For some reason when I draw a mesh using Graphics.DrawMesh, the vertices are all fucked up.
This is the function I use to make a mesh. It makes a quad and does it well. It's just the length of the quad is super long. IDK why. I'd love help.
 public Mesh generatedLine(Vector2 initial, Vector2 final, float width)
     {
         Mesh finalmesh = new Mesh();
         initial = transform.InverseTransformPoint(initial);
         final = transform.InverseTransformPoint(final); 
         Vector3 difference = final - initial;      
         float distance = difference.magnitude;
         Vector3 direction = difference / distance;
         float angle = Mathf.Atan(difference.y / difference.x);
         float theta = Mathf.Asin(width / distance) * 180 / Mathf.PI;
 
         if ((difference.y > 0 && difference.x < 0) || (difference.y < 0 && difference.x < 0))
         {
             angle += Mathf.PI;
         }
 
         float resultangle = angle + theta;
         
         Vector3 dpoint, apoint;
         dpoint = Quaternion.Euler(0, 0, theta) * (distance * direction);
         apoint = Quaternion.Euler(0, 0, theta + 90) * (direction * width);
         //apoint = transform.InverseTransformPoint(apoint);
 
         finalmesh.vertices = new Vector3[] { initial, apoint, final, dpoint };
         finalmesh.triangles = new int[] { 0, 1, 3, 0, 3, 2 };
 
         Color[] meshcolor = { Color.red, Color.red, Color.red, Color.red };
         finalmesh.colors = meshcolor;
         finalmesh.RecalculateBounds();
         return finalmesh;
         
     }
 
              
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Editing vertices 1 Answer
Unidirectional slicing algorithm of a mesh 0 Answers
Why vertex positions appear (0.0, 0.0, 0.0) ? 1 Answer
Mesh triangles don't match wireframe view? 0 Answers
How to add vertex points to a mesh 1 Answer