Search Unity

Physics2D.OverlapCircle and Composite Collider 2D

Discussion in 'Physics' started by PixelFireXY, May 3, 2020.

  1. PixelFireXY

    PixelFireXY

    Joined:
    Nov 2, 2011
    Posts:
    56
    Hi,
    I don't know if it's a bug or it meant to be like this, I just want to share this if you are in the same situation (or similar).

    I'm developing a 2D platform game, and on tilemaps, I'm using a Tilemap Collider 2D component, and to save resources a Composite Collider 2D.

    What I discover, if you try to detect the collider with Physics2D.OverlapCircle(or something else) you will detect only the edges of the tile collider, and not the inside of it.

    So, if you want to detect the inside of the collider too you have to use a separate tile with no composite component.

    Hope this will save you the time I wasted to discover this.
    Cheers.
     
    jagoorv4 likes this.
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,455
    You mean you're using Outline mode on the CompositeCollider2D which produces edges only (same as EdgeCollider2D) and edges don't have an "inside". :)

    As the docs state:
    This is a set of edges identical to the EdgeCollider2D therefore it's only edges you collide with unlike polygons that form a closed area. Take an EdgeCollider2D and define some edges but overlap the start/end points. It's still not a polygon, it's just a bunch of edges and no defined "interior".
     
    jagoorv4 and PixelFireXY like this.
  3. PixelFireXY

    PixelFireXY

    Joined:
    Nov 2, 2011
    Posts:
    56
    Thank you so much, this is refreshing! :)