2d - Check if point is within bounds, rotation

Hello, I need to detect when one object is within/inside another,


it works by checking bounds.Contains method (I check if bounds of green box, contains min and max bounds of yellow one)

However in my scenario, both boxes can be rotated, and it basically means following approach will be useless, since unity`s documentation says, bounds are:

> An axis-aligned bounding box, or AABB for short

is there any other method to calculate and detect that? I could use 2d colliders and detect that on collision enter, but I am looking for simpler way to calculate it.

Thank you.

If you just need to test a point vs a bound, transform the point into the same transformation space as the bound. Obviously you can’t use the renderer bounds since it keeps resizing. Perhaps a Rect would suffice.

If you need to to test two 2d boxes, you could do a simple line test for intersection, based from the corners of the box and if any line intersect, it overlaps. You can do a containment test such that if all 4 corners of box is inside the other box, it’s contained (no intersection occur in containment). Note that either of the boxes could be contained within the other so you need to make the test for both (is A contained in B or is B contained in A?).

These are general problems that isn’t Unity specific and you can find lots of examples online.

A simpler way might just be to use a BoxCollider2D, and use the provided functions IsTouching or OverlapPoint.