b2RevoluteJoint vs b2WheelJoint

General discussion about Box2D tutorials
Post Reply
vkreal
Posts: 66
Joined: Sun Jan 13, 2013 7:29 pm

b2RevoluteJoint vs b2WheelJoint

Post by vkreal »

Anyone have any opinions on b2RevoluteJoint vs b2WheelJoint for making vehicle wheels? I am a newb and trying to decide which to go with?

Thanks in advance!
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: b2RevoluteJoint vs b2WheelJoint

Post by iforce2d »

If you want to make anything resembling a modern vehicle with suspension, you would want the wheel joint. A revolute joint would be like an old wooden wagon wheel, quite a rough ride.

Apart from the smoothness of ride, the main difference from a game-logic point of view is that a wheel on a revolute joint will be continuously separating and touching the ground, even on flat areas, especially on a downslope. This can be a problem for trying to keep enough friction between the wheel and the ground. It will also give you a lot of BeginContact/EndContact events, even many per second, which could be a nuisance if you're trying to play sounds based on it.

By contrast a wheel joint with a reasonably soft suspension should keep the wheel and the ground pressed together more of the time, with less frequent contact changes.

I know some of the ports (box2dweb etc) don't have the wheel joint, but if you're using one that does I would say definitely use the wheel joint. If you can't, the next best thing is a line+distance joint combo. In the C++ version the line joint has been replaced by the wheel joint, but in some of the other ports it is still around. The line joint is basically a wheel joint with no motor or suspension (it just keeps the anchor point of body B on a line relative to body A). You can use a distance joint with it to act as suspension, using the same values as you would for a wheel joint. To turn the wheel, you will need to apply torque to it.
Post Reply