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?
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
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.
FYI: OverlapBox includes rotation whereas OverlapArea doesn't. OverlapArea will be deprecated eventually.
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?
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?
Yep! here... https://forum.unity3d.com/threads/physics2d-overlapboxnonalloc-inaccurate.451102/ (sorry!)
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?
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.