3

line renderer checked, tolerance 1, corner vertices and end cap vertices 5, alignment: view, texture mode: stretch,  shadow bias: .5

Image of Lines taken from unity

Line Drawn through mouse movement but curves are not smooth at all and this sort of line looks very ugly. I have tried to change settings of line renderer but nothing helps. I am stuck here and need some support... Below I have mentioned the code as well...enter image description here

public GameObject linePrefab;
public GameObject currentLine;
public LineRenderer lineRenderer;
public EdgeCollider2D edgeCollider;
public List<Vector2> fingerPosition;
void Update()
{
    if(Input.GetMouseButtonDown(0))
    {
        CreateLine();
    }
    if(Input.GetMouseButton(0))
    {
        Vector2 tempFingerPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        if(Vector2.Distance(tempFingerPos, fingerPosition[fingerPosition.Count -1]) > 0.1f)
        {
            UpdateLine(tempFingerPos);
        }
    }

}
void CreateLine()
{
    currentLine = Instantiate(linePrefab, Vector3.zero, Quaternion.identity);
    lineRenderer = currentLine.GetComponent<LineRenderer>();
    edgeCollider = currentLine.GetComponent<EdgeCollider2D>();
    fingerPosition.Clear();
    fingerPosition.Add(Camera.main.ScreenToWorldPoint(Input.mousePosition));
    fingerPosition.Add(Camera.main.ScreenToWorldPoint(Input.mousePosition));
    lineRenderer.SetPosition(0, fingerPosition[0]);
    lineRenderer.SetPosition(1, fingerPosition[1]);
    edgeCollider.points = fingerPosition.ToArray();
}
void UpdateLine(Vector2 newFingerPos)
{
    fingerPosition.Add(newFingerPos);
    lineRenderer.positionCount++;
    lineRenderer.SetPosition(lineRenderer.positionCount - 1, newFingerPos);
}
Laurel
  • 5,965
  • 14
  • 31
  • 57
Usama Aslam
  • 53
  • 1
  • 6

2 Answers2

2

You could try using an algorithm to smooth the line as you draw it such as Catmull-rom or Bezier but effectively the only way to make it look smoother is to add more points.

Here is a SO question that can help with CR splines

Simon Newman
  • 61
  • 11
1

Try putting a texture on your material that you use on line renderer. The texture is below. It looks white here, but if you open it in a new tab you'll see. This will help with aliasing on line borders.

line texture