collision-box rotated?

Started by
2 comments, last by suliman 16 years, 7 months ago
Hi I have vehicles that i wish to collision check vs projectiles. A vehicle has these properties: int2 pos; //the game is in 2D int2 size; //width and height float rot; //in radians So its easy to check the projectile (considered a simple point) vs a non-rotated rectangle but as my units turn how do i handle this? Thanks Erik
Advertisement
Imaging rotating the entire world about the 'pos' of the vehicle, by the negative of its 'rot'. Q. Where will the corners of the vehicle end up? A. Aligned, again (we cancelled out the rotation), and still centered on the 'pos'. Q. Where will the projectile end up? A. As if we had translated the centre of the vehicle to the origin, performed the rotation and then translated back. Q. Is the original projectile inside the vehicle? A. If and only if the moved-via-rotation projectile is inside the rotated vehicle (which you can check easily), since rotation and translation do not affect this property (you can turn a piece of paper whichever way you like or slide it around to anywhere, but crossed lines on the page are still crossed, and uncrossed lines are still uncrossed).
he?
maybe you know of a tutorial that goes through this step by step? Ive googled a bit but finds only tuts on specific game engines.

thanks
E
oh maybe i have an idea now... I could use the code I finally got working for offsetting I roteted body and just do the other way around... Maybe that was what you suggested :)

This topic is closed to new replies.

Advertisement