- Home /
Physics2D.OverlapArea not working at certain positions
Hi, I have a problem with Physics2D.OverlapArea.
I have a single game object with BoxCollider2D. I use Physics2D.OverlapArea to check whether the game object is in certain area. When I move the game object further from the world origin (e.g. y = 19) and check the area that my game object occupies, Physics2D.OverlapArea does not return a hit. This occurs only at some positions. The further I move the game object from the world origin, the more often this problem occurs.
My game object is at position -5, 19, 0. The size of its BoxCollider2D is 0.5, 1. It has this script attached to it:
void Update () {
var bounds = GetComponent<BoxCollider2D>().bounds;
var center = bounds.center;
center.y += 0.01f; //WITH SOME OFFSETS, IT WORKS; WITH OTHERS IT DOES NOT
bounds.center = center;
var result = Physics2D.OverlapArea(bounds.min, bounds.max);
Debug.Log(result);
}
the 'result' in the example is null. Thanks!
UPDATE:
It seems like the problem occurs only if the game object`s left edge has the same x position as the tested area`s left edge and the game object`s right edge has the same x position as the tested area`s right edge. The problem still occurs only at certain positions with y > 12+.
Can anyone help please? It really makes me frustrated :(