#### Archived

This topic is now archived and is closed to further replies.

# Car - Collision Response

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

## Recommended Posts

Hi, I was wondering if anybody has any details on how to handle collision response when a car hits a stationary object, i.e. a house, lamppost. I am writing a 2D style car game and all my attempts so far have been pretty rubbish. I have a vehicle which has a position, velocity, angular velocity, mass etc.. What I''m hoping to do is that a car will vear off a building when it hits it, so that if the car hits the building at an angle, it will rotate to point away from the building. If anybody knows a good way to do this I would be most grateful or of course a link to a good tutorial. Thanks in advance Jam

##### Share on other sites
Look up Box-Box 2d collisions. Have your world setup with boxes representing collidable objects. So once you have it knowing when the car collides wiht object you then need to apply the response.

The elasicity of a collision is a very simple formula you can find anywhere on the web. And once you get the resulting force, you then calculate the torque using a cross product and you are set.

I know it sounds easy, but it isn''t. It takes a bit of time and fine tuning, but for a simple 2d game it will likely be the toughest problem you will come across.

##### Share on other sites
i was making a car game, after i quit i worked out how to do it,
what you do is , you have an angle variable for the direction the car is moving, and another variable for its steering direction, so when you turn too sharply you still will be going in the current direction and slowly align the two angles to go straight again and stop sliding.

When you detect a collision, just add i think its 90 degrees to your direction angle and half the speed its moving at and i believe and you will bounce off the object in the right direction and at a slower pace for the collision would of halfed your speed or so if not stopped you

this will also allow your car to slide etc

edit:
if its 2D you could easily get the corners your car and use the CreatePolygonRgn i think its called, make that region around your car, then make regions for all your buildings etc ,

then you check if the two regions are colliding,

this is done by creating two regions, both which are combined of the car and the colliding object, but one is created with solid flag and other with xor flag i think it is.

the function is called combinergn

then check if the two regions you created arnt equal, if so it means you have collided!

[edited by - johnnyBravo on June 4, 2004 11:54:26 AM]

##### Share on other sites
the best tutorials I can think off are chris hecker''s physics articles, and this one

http://www.d6.com/users/checker/dynamics.htm
http://www.cs.unc.edu/~ehmann/RigidTutorial/

then after that, it''s pretty straight forward. what you need besides what you''ve already got is the inertia of the object.

a couple of demos as well...

http://uk.geocities.com/olivier_rebellion/box.zip
http://uk.geocities.com/olivier_rebellion/Cube.zip

go to the main page to get them if the link isn''t working.

##### Share on other sites
First of all you''ll definately need collision detection like jimmynelson says. However for a fast paced car game I think you''ll be pretty dissapointed if you use realistic collision responce since this will more than likely lead to your car coming to a complete stop and pointing directly at the offending obsticle every time. Not very player friendly and pretty fustrating to boot. Instead I suggest that when the vehicle is detected to be penetrating a polygon of an obsticle, you instead simply move the car back along the polygon normal direction until they are no longer intersecting. This way the car will slide along the poly (eg wall) without rotating to face the poly and coming to a complete stop. To add a bit of realism, every time the vehicle has to be shifted this way simply dock a bit of the vehicles speed. The amount docked can even be scaled by the angle between the cars direction and the poly normal so that more severe crashes result in the loss of more speed. Next time you''re playing any (non-sim) racers keep this in mind and you''ll probably find this is what most games do (eg crazy taxi). Hope this helps

1. 1
Rutin
38
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633350
• Total Posts
3011472
• ### Who's Online (See full list)

There are no registered users currently online

×