Search Unity

Physics.ComputePenetration *2D*

Discussion in 'Physics' started by lorenzoteslermabe, May 20, 2021.

  1. lorenzoteslermabe

    lorenzoteslermabe

    Joined:
    Dec 23, 2020
    Posts:
    24
    Hello!

    The ComputePenetration method is something that I would really like to have access to, but I am working in 2D. Is there any way I can get it to work with 2D colliders and such, or is there any such method for Physics2D?

    Thanks so much,

    Lorenzo
     
    DragonCoder likes this.
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,458
    Yes, you can use this. It tells you distance or overlap and the points on each collider.

    It's always worth looking through the API reference.
     
  3. lorenzoteslermabe

    lorenzoteslermabe

    Joined:
    Dec 23, 2020
    Posts:
    24
    Hey thanks! I was aware of this, but didn't realize that it contained more information than just the distance... my bad. Cheers!
     
    MelvMay likes this.
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,458
    Ah sorry, cool that you found it. It might be worth my getting some extra info on that page for discovered that highlights distance including negative distance (overlap).
     
  5. lorenzoteslermabe

    lorenzoteslermabe

    Joined:
    Dec 23, 2020
    Posts:
    24
    Yes I do think that getting this functionality more visibility in general would be a huge help to the community. I say this because I just implemented it and it works beautifully. This combined with my own overspeed handling has virtually eliminated any of those frustrating, head-scratching explosive collisions. Thanks again!
     
    Biviho and MelvMay like this.