Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am trying to implement the collision detection and response in 3D car racing game.

I have a car model, for collision I am assuming my car as a cuboid. my collision detection with walls is quite good and the response is also good. My model has a velocity, position, acceleration and orientation. I am using matrix to save the orientation and position.

My problem is collision and its response with the ground (in my case it's road). When the ground is a simple plane with a constant y-axis, then there is no need for collision detection as there is no force or movement in the y direction. But if my road is not linear, if it has some elevation, then I am having a collision detection problem when it comes to calculating its orientation.

Any help and suggestions will be of great help.

share|improve this question
    
On a naive level, how is colliding with the ground really any different than colliding with a wall? Depending on how realistic you want to go (I.e. Shock/strut simulations, drag, etc.) that should be enough to start. –  Tetrad Aug 10 '11 at 6:14
    
Actually with collision with the walls, in response i only have to control rotation of the car with respect to local y axis ( assuming z axis front, and y above ), while with collision with ground, in response i have to orient the car according to the ground with weight transfer). –  LebRon Aug 10 '11 at 6:27

1 Answer 1

up vote 3 down vote accepted

It looks like you don't want to use a car simulation middleware, or even a physics engine to model a "classic car" from a box, four spheres and some hinge joints for the suspension. Well then, I guess for a simple solution you could try something like this:

  • Take your cuboid's bottom plane.
  • Cast 4 rays downward from each of its's corners and find their collisions with road. This collisions will be your "imaginary wheels".
  • Now you can make a height check to hold the car at the right distance from the road (the radius of the imaginary wheel), then set cuboid's lower plane's corner coordinates to the new found wheel's positions. It will be a somewhat working solution, but also give a unique feeling of driving a large concrete brick.

    • For a more realistic approach you may want to simulate a spring system at each imaginary wheel to make it a bouncy concrete brick. Maybe you will also replace wall collisions with it.
    • Then you may want to simulate friction of imaginary wheels. To this point your car was glued to the road, but now it will start to roll-over. Roll overs can be battled with artificial anti-sway torque and GTA-like modifying of max correctional torque by the amount of "wheel turn value", so a player would be able to steer out of roll-over. Unrealistic yet funny :)

Things will quickly become more and more complicated here, it won't be easy to make a fun car physics. Nowadays most if not all physics engines have a built-in car class with tweakable parameters, so you may want to look at their sources.

share|improve this answer
    
Thanks for your reply, when we cast four rays downward from each of it's corner then we get 4 new points, but a plane will satisfy only 3 points, how can we set the bottom plane on all the four points? –  LebRon Aug 10 '11 at 10:57
    
can you please tell me any free physics engine which has quite realistic built in car class, i am using c++. –  LebRon Aug 10 '11 at 11:00
    
I don't think I understood your first question correctly, but with my naive approach there may be a lot of cases when you won't be able to position all four wheels on a road without car's bottom itself intersecting with road. You can fix it with hacks, but overall for complex roads with complex mechanics it may be better to use a PhysX. I'm sure it had a car tutorial and sources. –  Vigil Aug 10 '11 at 11:16
    
Also a bit about realism. Different games will have different meaning of this word, so even with physics engine you will have a lot of tweaking to do. It seems that i've been advocating NeoAxis a bit lately, but it has this little plugin called NMechanics, you may want to check it out: nmechanics site –  Vigil Aug 10 '11 at 11:34
    
actually i want to say that after we cast four rays, we get four new tyre positions as a result. But as you said " then set cuboid's lower plane's corner coordinates to the new found wheel's positions" , my question is as a plane equation needs only three points, its not sure that the fourth point will satisfy the plane equation, how can we select the three points? –  LebRon Aug 11 '11 at 11:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.