Search Unity

Physics2D.OverlapBox bugged?

Discussion in '2D' started by SSStiven, Aug 9, 2016.

  1. SSStiven

    SSStiven

    Joined:
    Aug 9, 2016
    Posts:
    11
    I can use Physics2D.OverlapCircle without problems , but when I try to use Physics2D.OverlapBox I get this error:

    Error CS0117: 'UnityEngine.Physics2D' does not contain a definition for 'OverlapBox' (CS0117) (Assembly-CSharp)

    http://docs.unity3d.com/ScriptReference/Physics2D.OverlapBox.html

    Is OverlapBox bugged?? Any suggestion?
     
  2. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    You want OverlapArea, give it the min corner and max corner of a rectangular area.
     
  3. SSStiven

    SSStiven

    Joined:
    Aug 9, 2016
    Posts:
    11
    Thank you for your answer, but why OverlapBox doesn't work?
     
  4. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    A box is a 3 dimensional check. An area is a 2 dimensional check.
     
  5. Vol4ica

    Vol4ica

    Joined:
    Jun 5, 2016
    Posts:
    2
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Because that's only in Unity 5.4 and later, and the OP would have been using an earlier version (not too surprising back in August, but the actual answer should have been "upgrade your Unity"). The Physics2D version is different from the Physics version.

    --Eric
     
    LiterallyJeff likes this.
  7. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    Indeed, I should've verified my assumptions about the API before leaving my previous replies. Sorry for any confusion.
    Ignore what I previously said, there is indeed a 2D box check. The difference between box and area is in the parameters it takes to define the area checked.
     
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,455
    FYI: OverlapBox includes rotation whereas OverlapArea doesn't. OverlapArea will be deprecated eventually.
     
    LiterallyJeff likes this.
  9. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Finding it really buggy in 5.6 - known issue? it is firing at any angle I pass - unless angle is supposed to be radians or something?
     
  10. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,455
    Not a bug, collision normal angle isn't used for overlap checks because there isn't collision normal, it's an overlap check not a cast or contact query that has a 'normal' to compare with. I believe it's mentioned in the doco but it's not very prominent; the doco has some updates on the way.

    Should this've gone in a separate post? ;)
     
    Last edited: Jan 14, 2017
  11. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
  12. Prantare

    Prantare

    Joined:
    Oct 15, 2017
    Posts:
    2
    If one does not need rotation (e.g. using many axis aligned rectangles), would you mind keeping a version that doesn't require an angle for performance, simplicity, and clarity?
     
  13. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,455
    Note that this post was in Jan this year and the "Area" method is still there as we decided to keep it instead. Also, there's no performance difference related to angle; the internal check is done with a box anyway but just implicitly at zero angle.