Search Unity

Question PolygonCollider2D How to detect separeted islands?

Discussion in 'Physics' started by LaserRock, Feb 17, 2023.

  1. LaserRock

    LaserRock

    Joined:
    Jan 2, 2018
    Posts:
    13
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,491
    What do you mean by "detect"? Physics collision detection doesn't report specific "islands" because to it, they don't exist. It only understands the convex polygon shapes that are produced i.e. all the shapes on a collider.

    You can read the shapes back that are produced from any collider but that's it.

    https://docs.unity3d.com/ScriptReference/Collider2D.GetShapes.html
     
  3. LaserRock

    LaserRock

    Joined:
    Jan 2, 2018
    Posts:
    13
    I need to know which shapes form the outer ring and which form the center.
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,491
    Yes, that's just another way of saying "detect" but it doesn't explain further exactly what you mean in terms of the code or engine. Detect using physics queries, collision callbacks, read the shapes and figure it out?

    In the end, what I said above is still true in that the physic system doesn't distinguish it.
     
    Manjunku likes this.
  5. Manjunku

    Manjunku

    Joined:
    Jun 13, 2021
    Posts:
    8
    Hello there, i guess i've got the same question.

    Actualy i need to detect island to make dynamic destructible sprites, like Worms terrain but the islands created by player's destruction becomes physicals debris.

    So i would like to know wich is the more effective way to detect islands. Maybe it's not through the collider but my guess was to make an algorithm with the vertices stored in the collider. Wich sounds like a bad idea regarding what you said @MelvMay

    I found this :

    https://assetstore.unity.com/packages/tools/physics/advanced-polygon-collider-52265
     
    Last edited: Apr 27, 2023
  6. Manjunku

    Manjunku

    Joined:
    Jun 13, 2021
    Posts:
    8
    So sad there's no more the detect island checkbox in the asset, and the sources are not available :(