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 want to develop a simple car racing game where the road is defined by a heightmap. It looks basically like this:

2d car racing game

The player can use throttle and brake to control the car.

I'm wondering what the best approach for the physics is. I have some ideas:

  • Use a mass-spring system with one mass for each wheel.

    Pro: Gravity affects each wheel independly, so if one wheel stands on ground and the other one floats in the air, the car rotates. Can be extended to three dimensions by adding two more wheels.

    Contra: The distance between the weels varies. The system may explode (when forces amplify each other). The car will fall down if both wheels float, but the middle of the car touches ground.

  • Define the car's state using position, momentum, rotation and spin.

    Pro: The wheel distance is constant, no springs included

    Contra: very complex, hard to compute, not really extensible to a third dimension

I think there must be a better way than those.

share|improve this question
4  
"Later, I want to add a third dimension" What? –  Liosan Feb 1 '13 at 9:23
    
I hope I can use the same technology (or at least the basic idea) in a three-dimensional race game later. –  Yogu Feb 1 '13 at 9:27
1  
Ok, forget the thing about third dimension, it was only an idea... any constructive comment? –  Yogu Feb 1 '13 at 21:11
    
How did you come up with the Pro and Contra arguments? Using rigid body physics is actually easier and more stable than tweaking stiff springs for your car (and it won't be very pleasant). Undoubtedly, Box2D can do the hard work for you: emanueleferonato.com/2009/04/06/two-ways-to-make-box2d-cars . –  teodron Oct 16 '13 at 16:07
    
Thanks, @teodron! The second example was exactly what I was looking for. It uses springs, but I don't know if they are required. –  Yogu Oct 16 '13 at 17:26

1 Answer 1

up vote 1 down vote accepted

If you want to apply physics, you have to use physical engine. I would recommend you to use Box2D which is a good 2D physical engine for C++ or JBox2D which is the Java version of Box2D. If you want a 3D physical engine I think Bullet is a nice one. There are lot of tutorials about all of them, just google it (I can't add more hyperlinks).

share|improve this answer

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.