private bool WrapWireAroundObstacles(float2 a, float2 b, int insertAt) { var added = false; var offset = new float2(0, 0.075f); var hit = Physics2D.Linecast(a + offset, b + offset, GroundMask); if (hit) { float2 point = hit.point; var foundValid = false; if (hit.collider is PolygonCollider2D polygon) { point = Physics2DUtility.GetClosestPointFromPoint(hit.point, polygon); foundValid = true; } else if (hit.collider is CompositeCollider2D composite) { try { point = Physics2DUtility.GetClosestPointFromPoint(hit.point, composite); foundValid = true; } catch { foundValid = false; } } if (foundValid && NotTooSimilarToLast(point)) { Placed.Insert(insertAt, new Point { Value = point }); if (DrawGizmos) { DebugDraw.Sphere(new float3(point, 0), 0.15f, Color.red, 3f); } added = true; } } if (DrawGizmos) { Debug.DrawLine(new float3(a + offset, 0), new float3(b + offset, 0), Color.blue); } return(added); }