Answers for "LineRenderer creating triangles instead of lines"
http://answers.unity.com/questions/757037/linerenderer-creating-triangles-instead-of-lines.html
The latest answers for the question "LineRenderer creating triangles instead of lines"Answer by Zodiarc
http://answers.unity.com/answers/1257607/view.html
If you don't need the line to be blocky, you can use the Chaikin path smoothing algorithm http://graphics.cs.ucdavis.edu/education/CAGDNotes/Chaikins-Algorithm/Chaikins-Algorithm.html
It will produce a nicely smooth curve.Mon, 17 Oct 2016 09:20:32 GMTZodiarcAnswer by MaLlorente
http://answers.unity.com/answers/1257601/view.html
Hi @Grin and @jbarbeau,
As you can read [here][1]. The problem is that a line render is a mesh and Unity optimize the mesh by reusing some vertex. The result is that ugly triangle shape.
You can solve this by
1. Creating more points to smooth the edges. Its not an elegant solution but its simple and works, at least for me. I wrote a function that do that:
Vector3[] Generate_Points(Vector3[] keyPoints, int segments=100){
Vector3[] Points = new Vector3[(keyPoints.Length - 1) * segments + keyPoints.Length];
for(int i = 1; i < keyPoints.Length;i++){
Points [(i - 1) * segments + i - 1] = new Vector3(keyPoints [i-1].x,keyPoints [i-1].y,0);
for (int j = 1;j<=segments;j++){
float x = keyPoints [i - 1].x;
float y = keyPoints [i - 1].y;
float z = 0;//keyPoints [i - 1].z;
float dx = (keyPoints [i].x - keyPoints [i - 1].x)/segments;
float dy = (keyPoints [i].y - keyPoints [i - 1].y)/segments;
Points [(i - 1) * segments + j + i - 1] = new Vector3 (x+dx*j,y+dy*j,z);
}
}
Points [(keyPoints.Length - 1) * segments + keyPoints.Length - 1] = new Vector3(keyPoints [keyPoints.Length-1].x,keyPoints [keyPoints.Length-1].y,0);
return Points;
}
2. (Solution copied form [here][2])Coding your own line renderer, and not make it so economical. You can do this by generating a dynamic mesh. The mesh will consist of a series of thin quads. For each line segment, you can compute the four corners of the quad by calculating the normal of the line and a specified line width:
Vector3 normal = Vector3.Cross(start, end);
Vector3 side = Vector3.Cross(normal, end-start);
side.Normalize();
Vector3 a = start + side * (lineWidth / 2);
Vector3 b = start + side * (lineWidth / -2);
Vector3 c = end + side * (lineWidth / 2);
Vector3 d = end + side * (lineWidth / -2);
[1]: http://gamedev.stackexchange.com/questions/93823/how-to-make-line-renderer-lines-stay-flat
[2]: http://gamedev.stackexchange.com/questions/93823/how-to-make-line-renderer-lines-stay-flatMon, 17 Oct 2016 09:17:25 GMTMaLlorenteAnswer by jbarbeau
http://answers.unity.com/answers/778483/view.html
![alt text][1]
I'm having the same problem with LineRenderer. The first segment renders a triangle, unless I look at the other side. From that perspective it's a rectangle. The last segment is always a rectangle.
I've played with linewidth etc, Here's my code:
lineRenderer.SetVertexCount (3);
lineRenderer.SetPosition (0, new Vector3(0.0f,0.0f,0.0f));
lineRenderer.SetPosition (1, new Vector3(5.0f,5.0f,5.0f));
lineRenderer.SetPosition (2, new Vector3(7.0f,2.0f,6.0f));
lineRenderer.SetWidth(0.1f,0.1f);
Does anyone have an answer? Are there 2 sides to the line? It's a billboard that always faces you.
One side renders a triangle, the other side renders a rectangle look at pics the underside pic.
![alt text][1]
[1]: /storage/temp/31526-drivingrange_linerenderer3.jpgMon, 25 Aug 2014 22:09:27 GMTjbarbeau