# rotation inside a tiled enviroment

This topic is 4850 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a tiled collision system using rectangle shaped entities, does anyone know a simple way of rotating a given rectangle that will still conform to the tiled collision system? the width and height will differ, but this is just a 2x4 example purrty example: ..XX.. ..XX.. ..XX.. ..YX.. rotated 90' right .... YXXX XXXX .... rotated 45' right ..XX .XX. .XX. YX.. Any algorithms come to mind? I'm hoping for a speedy solution, but I may just have to give it up, this is for tiled based vehicles with rotations of 45'. I don't want to have to settle for square cars or changing the system entirely :< plx assist mathgods! (mods feel free to move if its not mathematical enough for this section.)

##### Share on other sites
So the vehicles can only be oriented at multiples of 45 degrees? I can't think of an easier general solution than SAT (separating axis theorem). You could probably special-case the code nicely given the restrictions on the environment, though. However, once you get the system in place, arbitrary orientations will be just about as easy as mults of 45 degrees. Unless it's sprite based of course, in which case you may have a good reason for restricting the rotations.

Remember that changing direction may bring a vehicle into penetration with an obstacle. So whenever the direction changes you should probably disallow the change if this happens. Otherwise (assuming you're using collision resolution based on penetration depth) the vehicle might 'push away from' the wall in an unnatural manner.

Well, I don't know if that helps at all, but let us know if you need more specific advice...

##### Share on other sites
Well, the 3D vehicles are models and go through 360 degrees, but the collision system is in tiles. So it may as well be 45' degrees.. maybe I should just hardcode it, just wondered if anyone had a generic formula.

Thanks for your help

##### Share on other sites
This is actually something of a rasterization problem, but instead of rendering to the screen you're "rendering" to the collision space. Store all your data and do all the transformations is real numbers, then once you're ready for them to be collided rasterize them into your collision space using standard algorithms (such as Bresenham for lines, etc.).

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 28
• 16
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
634113
• Total Posts
3015570
×