So if I had 4 Vector2 variables defining the four corners of a rectangle. What would be the best way to detect if another Vector2 defines a point that is inside that rectangle IF the rectangle is rotated like this:
Im currently thinking I will rotate the entire system about a corner of the rectangle to make everything line up with the axis, and therefore more simple of a calculation to determine if the point is actually inside the rectangle. But does someone know a better method? Better meaning faster to process, I’m not too concerned with complexity of code.
Having 4 seperate Vector2 points doesn’t necessarily represent a rectangle but simply a polygon.
It would be slightly easier to define your rectangle as one point and two direction vectors with the approppriate length of your rectangle. That way all you have to do is projecting the point onto those two vectors and check the range.
Another was to define your rectangle is to use an actual gameobject and use the Transform class to define the point of rotation as well as the rotation. Now you can define the rectangle in local space. To test a point you can use InverseTransformPoint to transform a worldspace point into local space. In local space you can simply do an AABB check.
If you want to check against a polygon have a look at this.