public void smoothLine() { Debug.Log("Start SmoothLine"); if (line.positionCount > 3) { for (int i = 0; i < line.positionCount - 2; i++) { bool isOnLeftEdge = colliderNormals.ContainsKey(i) && !colliderNormals.ContainsKey(i + 2); bool isOnRightEdge = colliderNormals.ContainsKey(i + 2) && !colliderNormals.ContainsKey(i); if (!isOnLeftEdge && !isOnRightEdge) { var p1 = GetPosition(i); var p = GetPosition(i + 1); var p2 = GetPosition(i + 2); if (Vector3.Distance(p1, p2) * Statics.smoothFactor < Vector3.Distance(p1, p) + Vector3.Distance(p, p2)) { var midPoint = Vector3.Lerp(p1, p2, 0.5f); Vector3 midNormal = Vector3.back; if (line.hasNormals) { midNormal = Vector3.Lerp(line.GetNormal(i), line.GetNormal(i + 2), 0.5f); } RaycastHit2D hit = Physics2D.CircleCast(p1, Statics.lineThickness * 0.5f, p2 - p1, Vector2.Distance(p1, p2)); if (hit.collider != null && hit.collider.isTrigger == false) { //Nothing } else { SetPosition(i + 1, midPoint); if (line.hasNormals) { line.SetNormal(i + 1, midNormal); } } } } } } Debug.Log("End SmoothLine"); }