Comments and answers for "LineRenderer End Width Bug"
http://answers.unity.com/questions/909428/linerenderer-end-width-bug.html
The latest comments and answers for the question "LineRenderer End Width Bug"Comment by HZ51 on HZ51's answer
http://answers.unity.com/comments/1524397/view.html
Thanks a lot for that code. You saved my life :)Mon, 02 Jul 2018 04:37:37 GMTHZ51Answer by Lewwwer
http://answers.unity.com/answers/1216922/view.html
Hi all!
I know it's an old post but I met with this problem in my game and based on @NoseKills 's solution I made a function adding some extra points to a Vector3 array in order to display lines correctly.
Vector3[] solution(Vector3[] original)
{
Vector3[] res = new Vector3[original.Length * 3 - 2];
for (int i = 0; i < res.Length; i++)
{
if (i % 3 == 0)
{
res[i] = original[i / 3];
}
else if (i % 3 == 1)
{
res[i] = Vector3.Lerp(original[(i - 1) / 3], original[(i + 2) / 3], 0.0001f);
}
else if (i % 3 == 2)
{
res[i] = Vector3.Lerp(original[(i + 1) / 3], original[(i - 2) / 3], 0.0001f);
}
}
return res;
}
Basically it puts extra points before and after every positions, so the lines between them will be rendered correctly.
In my game I wanted to make a star of lines centered at the gameObject and pointing to each element of an array of GameObjects. I will post it here to show how to use this function:
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(LineRenderer))]
public class StarLine : MonoBehaviour {
public GameObject[] targets;
private LineRenderer lr;
private Vector3 pos;
void Start ()
{
lr = GetComponent<LineRenderer>();
}
void Update ()
{
pos = transform.position;
Vector3[] points = new Vector3[targets.Length*2];
for (int i = 0; i < points.Length; i++)
{
if (i % 2 == 0)
{
points[i] = targets[i/2].transform.position;
}
else
{
points[i] = pos;
}
}
Vector3[] good = solution(points);
lr.SetVertexCount(good.Length);
lr.SetPositions(good);
}
Vector3[] solution(Vector3[] original)
{
Vector3[] res = new Vector3[original.Length * 3 - 2];
for (int i = 0; i < res.Length; i++)
{
if (i % 3 == 0)
{
res[i] = original[i / 3];
}
else if (i % 3 == 1)
{
res[i] = Vector3.Lerp(original[(i - 1) / 3], original[(i + 2) / 3], 0.0001f);
}
else if (i % 3 == 2)
{
res[i] = Vector3.Lerp(original[(i + 1) / 3], original[(i - 2) / 3], 0.0001f);
}
}
return res;
}
}
I hope it helps solving this problem in the future!Sat, 16 Jul 2016 13:47:55 GMTLewwwerComment by NoseKills on NoseKills's answer
http://answers.unity.com/comments/909971/view.html
Yeah that's it. I can't remember my findings exactly anymore, but maybe even just adding 2 nodes at the same spot might do it.
I was doing this for a 2D match 3 game a la Jelly Splash so my case was a bit simpler, but I'd believe the same solution should workWed, 25 Feb 2015 18:11:29 GMTNoseKillsComment by sk00ter on sk00ter's answer
http://answers.unity.com/comments/909798/view.html
Interesting. So every time the laser "bounces" you add a very small new segment by adding a new node very close to the raycast hit.point? And thank you :)Wed, 25 Feb 2015 14:41:27 GMTsk00terComment by sk00ter
http://answers.unity.com/comments/909792/view.html
No if I draw the points manually the laser widths are fine and remain constant, but drawing them manually defeats the purpose behind the mechanics I intend for this game. :/Wed, 25 Feb 2015 14:37:49 GMTsk00terAnswer by NoseKills
http://answers.unity.com/answers/909773/view.html
The linerenderer draws the line pretty much with quads and because it needs to make the flat end of each segment match with the start of next segment, it needs to tilt the quads/triangles that make the line, thus the segments are not always facing camera.
I've been able to get satisfying results by adding 2 nodes instead of one to each spot where the line changes direction. Not sure if that always works.
P.S. nice looking game :)Wed, 25 Feb 2015 14:13:08 GMTNoseKillsComment by siaran
http://answers.unity.com/comments/909704/view.html
does this also happen if you just use your linerenderer to draw a line where you just set the locations manually and nothing happens to it code-wise?Wed, 25 Feb 2015 12:32:41 GMTsiaran