Is it really so difficult to draw smooth lines in Unity?

后端 未结 6 993
醉话见心
醉话见心 2021-02-03 10:51

I been trying for a while to draw smooth lines in Unity but with Line Renderer I obtained only jagged lines with the corners not rounded, in particular when the angle of curvatu

6条回答
  •  太阳男子
    2021-02-03 11:07

    You can get some good results by generating a mesh from a set of points.

    The algorithm for it is as follows:

    1. You have a set of points, could be generated with bezier curve.

    1. For each point, take a directional vector to the next point v = (p2 - p1) (marked in blue). Then rotate that vector by 90 degrees normal = v.y, -v.x marked in red.

    1. This illustrates that we will use each normal from the point position. You can now multiply this vector in both directions by the desired width of the line.

    1. Create the vertices at those positions.

    1. Add indices to form triangles. It will be something like [i, w/2 + i, w/2 + i + 1] where i is the current index, and w is the total number of vertices.

    1. Create the other triangles. Again something like [i, w/2 * i + 1, i + 1]

    1. And the final result. You can add more points to make the line smoother.

提交回复
热议问题