Is it possible to create a 2D Polygon Collider & Mesh that contains an internal enclosed gap?

Hello,

As my title states, is it possible to create a PolygonCollider2D and Mesh such that there is a gap or hole that is completely within the outer boundary of the shape the collider/mesh is mimicking? A simple example would be a donut/torus shape, with a circle cut out of the geometry in the middle. The boundary points have to be calculated during script startup as well.

Have you tried the obvious way of just wrapping the collider around an area in the middle that it excludes? It worked for me.

Hi Kurt thank you for the reply but I’m not quite sure I follow. I have a rectangle around which I need to generate a set of colliders & meshes, excluding the area that the rectangle takes up along with the space taken up by each inner collider/mesh (please see the attached pic):7483652--920543--Colliders.png

I need each collider & mesh to only take up the space shaded by the yellow/blue/red colors, respectively but it seems to me right now that a PolygonCollider2D can’t have any internal gaps or spaces. Is this not the case? Are you able to tell a PolygonCollider2D to ignore a region of space, thereby creating the necessary gaps?

This is how I would do it: close up that gap in the upper left.

Yes, use opposing windings for your paths. If the outer winding is clockwise, make the inner one anti-clockwise; that’ll form a hole.

1 Like

Thanks guys for the replies - I wound up creating an inner- & outer-bounds set of points as suggested to define the shape and the PolygonCollider2D correctly interpreted my points. From there I was able to generate a set of triangles using the built-in PolygonCollider2D.CreateMesh() function - instead of the old Triangulator code - to create the mesh data and now I have a functioning set of ring meshes & colliders.

2 Likes