- Home /
[2D] How to get gameobjects within a tilted rectangle area
Hi, all. I'm working on a top-down 2D game which has ranged attacks in shapes of circle, arc, and rectangle.
Circle and arc ranged attacks are done with Physics2D.OverlapCircleNonAlloc
to detect gameobjects within the range.
The problem is a rectangle ranged attack.
I tried Physics2D.OverlapAreaNonAlloc
for a rectangle ranged attack, but it doesn't work as I expected to get a tilted rectangle range. Since Physics2D.OverlapAreaNonAlloc requires top-left and bottom-right corner positions of a rectangle as variables, the rectangle is always straight up.
I want to get a tilted rectangle range.
Is there any way to get this?
I only want get a range in one frame for a performance reason, so attaching a box collider to the detecting gameobject seems not fine. But if it is the only way, I'd go with it.
Sorry for my bad English in advance. Thank you.
Your answer
![](https://koobas.hobune.stream/wayback/20220612120826im_/https://answers.unity.com/themes/thub/images/avi.jpg)