I have a 2d-top-down-unity game where the player is on an island. The shape of the island is random generated and he is not able to "escape" from the island.

So which Collider should I use for realizing this?

Is there some form of an "inverted" collider? Are colliders able to have a hole in them? Or should I create a polygon collider with a small gap (This could be quite difficult if the polygon bends the wrong way)?


An EdgeCollider2D would handle this case well.

Much like a LineRenderer, you provide it a list of points to join into line segments, marking your collision boundary. It can be a closed shape, but it is not required to be closed.

  • \$\begingroup\$ This seems easy to use. But isnt it dangerous concerning glitching if the player is very fast or hits excactly the point where the beginning and the end connect? \$\endgroup\$ – Gener4tor Jun 15 '20 at 14:19
  • \$\begingroup\$ You can overlap the beginning and end if you like. For fast players you can add a radius to the edges, or use sweep checks to constrain your movement, or continuous collision detection to try to minimize tunnelling. If that doesn't solve your problem then breaking the out of bounds area into polygonal chunks may be your next best bet. \$\endgroup\$ – DMGregory Jun 15 '20 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.