Sign in to follow this  
Teddy1991

Rotating collision rectangles help please

Recommended Posts

Hi, I'm new here and am having problem with a game I am trying to make. I have started to make a very simple 2D racing game and I have made a collision Rectangle that follows the car object. The collision works fine when I go directly vertical into a barrier but as soon as I rotate the car the collision rectangle doesn't rotate with it. I have looked all over for how to rotate a collision rectangle with the car but I couldn't find any helpful solutions. How I have made the game is I have rows of tyres that I simply placed on top of the background and made them each a collision rectangle. Here's an image of the track and highlighted in red are the collision rectangles. http://i45.photobucket.com/albums/f97/teddy1991/Untitled-2.jpg Below is another image but shows how I think the collision rectangle for the car is reacting to the rotation of the car. http://i45.photobucket.com/albums/f97/teddy1991/Untitled-3.jpg I am just clueless at the moment on how I could rotate the collision rectangle alongside the car. Any help would be appreciated. Thank you.

Share this post


Link to post
Share on other sites
It's kinda tricky and math heavy to implement, but the separate axis theorem is the best way of performing OBB collisions (Oriented Bounding Box, basically anything with sides not aligned to the X and Y axis). You can find some good resources and information by searching google or GD.net for Separate Axis Theorem or OBB Collision.

Share this post


Link to post
Share on other sites
Thank you for replying.

I didn't really want to look into anything too complicated, I'm new at programming and this seems pretty advanced from what I've seen from searching google.

Is there any other way of doing it that would be easier to do for a noob?


Share this post


Link to post
Share on other sites
Quote:
I didn't really want to look into anything too complicated..Is there any other way of doing it that would be easier to do for a noob?

Actually, no. Collision detection, even with AABBs, is somewhat complicated. That's why there are so many posts here on gamedev concerning various methods of collision detection.

You did search here on the site, right? [WINK]

If you use spheres, collision detection becomes pretty easy - comparing distances between sphere centers.

Share this post


Link to post
Share on other sites
As Buckeye indicated, the SAT is about as easy as it gets for oriented boxes, and once you introduce collision resolution (i.e. keeping your car from interpenetrating with obstacles), even the SAT is pretty complicated.

You could just use axis-aligned boxes or spheres, as suggested, but for an 'elongated' object such as a car, the inaccuracy could be noticeable.

Another (and recommended) option would be to use a third-party physics engine, such as Box2D (which would easily handle the scenario shown in your images).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this