Search Unity

Question Physics2D.OverlapCircle -- Depth doesn't work

Discussion in 'Physics' started by KarlKarl2000, Nov 8, 2022.

  1. KarlKarl2000

    KarlKarl2000

    Joined:
    Jan 25, 2016
    Posts:
    606
    [ UPDATE ] -- figured it out ... I needed to add a collider to this object ----

    Hello all

    I can't seem to wrap my head around overlapcircle
    https://docs.unity3d.com/ScriptReference/Physics2D.OverlapCircle.html

    I don't understand how minDepth & maxDepth works.. Can someone help explain this to me?

    This is the explanation in the documents.
    Thanks!

    Current outcome: _hitWall = TRUE when object is at -10 in Z Space
    Expected outcome: _hitWall = FALSE when object is at -10 in Z Space

    Code (CSharp):
    1.  
    2. layerMask _platformLayer;
    3. bool  _hitWall;
    4.  
    5. _hitWall = Physics2D.OverlapCircle(
    6.             transform.position, 1, 1 << _platformLayer.value, -1, 5 );
    7.  
    8.  
     
    Last edited: Nov 8, 2022
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,491
    If I had $1 for every title that stated physics didn't work and had to give $10 for when physics didn't work, I'd be a rich man. ;)

    In all seriousness though, this depth function isn't implemented specifically for this query, the same code that filters stuff runs for every single query you can make in 2D physics so any filtering by LayerMask, depth, contact normal (etc) wouldn't work for all queries.

    Note that you should consider using the overloads that accept a ContactFilter2D because not only is this a consistent and simpler way to configure what you get, it can also be placed as a public field so you can configure it in the inspector.
     
  3. KarlKarl2000

    KarlKarl2000

    Joined:
    Jan 25, 2016
    Posts:
    606