Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question 2D Physics - Best way to check a Donut Shape for colliders?

Discussion in 'Physics' started by RedCabinGames, Dec 13, 2022.

  1. RedCabinGames


    May 8, 2016
    What is a good way to check for colliders in a donut shape?

    My first thought was to use two Physics2D.OverlapCircle() and subtract the inner results from the outer results. But objects that overlap from the donut shape to the inner circle will be removed.

    Donut ExplanationSmall.png
    In the example image the Green(A) and Yellow(B) colliders should be detected, while the Red(C) is discarded.

    Another way I can think of is to make this a PolygonCollider with a cutout, but that would change the thickness of the donut ring when it scales, it would be nice to have control over that.

    Any ideas?