2
\$\begingroup\$

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.

\$\endgroup\$
7
  • 4
    \$\begingroup\$ "Later, I want to add a third dimension" What? \$\endgroup\$
    – Liosan
    Feb 1, 2013 at 9:23
  • \$\begingroup\$ I hope I can use the same technology (or at least the basic idea) in a three-dimensional race game later. \$\endgroup\$
    – Yogu
    Feb 1, 2013 at 9:27
  • 1
    \$\begingroup\$ Ok, forget the thing about third dimension, it was only an idea... any constructive comment? \$\endgroup\$
    – Yogu
    Feb 1, 2013 at 21:11
  • \$\begingroup\$ 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 . \$\endgroup\$
    – teodron
    Oct 16, 2013 at 16:07
  • \$\begingroup\$ Thanks, @teodron! The second example was exactly what I was looking for. It uses springs, but I don't know if they are required. \$\endgroup\$
    – Yogu
    Oct 16, 2013 at 17:26

1 Answer 1

1
\$\begingroup\$

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).

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .