BoxCollider2D bounds.Contain (somePoint) does not work as expected

I have a little problem with BoxCollider2D. When I do this:

bool someBool = someBounds.Contains(somePoint);

I get the expected result when the body has no rotation, as in picture 1. (the red area is where somePoint makes someBool true) And when the body is rotated, somePoint makes someBool true everywhere inside the red area (Fig. 2). I do not want this behavior. I want the dot to return to the green area (Figure 3).

Picture

+4
source share
1 answer

To achieve your goal, use BoxCollider2D.OverlapPointas follows:

bool overlaps = myBoxCollider2D.OverlapPoint (somePoint);

bounds of BoxCollider2D , AABB - " ", , 1. , 1 2 .

: BoxCollider2D , Bounds, Bounds, , .

+2

Source: https://habr.com/ru/post/1628476/


All Articles