I'm working not a game, and since I couldn't find good collision detection method for detecting collision with rotated rectangles, I decided to try something like this: I have a rotated rectangle (which I suppose I can get its corners' coordinates (maybe some function of CGRect or trigonometry if necessary) I want to get all the coordinates along the line connecting two of the corners (even just the int values, or with a certain increment so it won't get too long) and get them into an array. then I can check for the containing rectangle of the ball which its bounding rectangle doesn't rotate) if it contains the any point of the array. if it does, they collided.
Is there an easy way of getting these coordinates into an array? assuming I know the start and end? I understand it will be not quite efficient, but right now I'm using the OpenGL color detection, and it is too kinda slow, and not working well, so I'm kinda in a need of a new method.
Thanks!
You already have the lines via the edges of your rectangle. Just take the X,Y coords of your 4 corner and you have your 4 lines.
Generally with collision you can almost always find a way to fake it, I would only bother using a rotated rect for the collision if you really need it, a lot of the time you can take what looks like a rectangle and just give it circular collision.
If you are sticking with the rotated rect another approach you can try is to apply the inverse rotation to both objects, then check the collision. So if the rect is rotated 45 deg, rotate the rect back -45 degrees so it is axis aligned, then also rotate the center of the circle -45 degrees. Now you have a much simpler collision to work with.
You can get more here: Circle-Rectangle collision detection (intersection)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With