Box2D Friction Joint Mod (for cars and such)

A Box2D joint for top-down friction

This was a side project to implement a missing feature in Box2D which I needed in my object dynamics research. That project required 2D anisotropic friction ("wheel constraints") to model arbitrary planar object dynamics, but Box2D only supported isotropic friction (the difference being whether it's possible to define separate coefficients in the X and Y directions). Because my project is in python, I also updated the swig bindings in pybox2d. Code and patchfiles (against Box2D 2.2.1 and pybox2d r358) can be found here.

Explanation

According to documentation and Erin's comments online, the FrictionJoint class was implemented in a fairly recent version of Box2D to provide modelers a way of simulating friction in top-down worlds (Box2D is really meant for vertical simulations, like Angry Birds). However, despite citing MikeRLewis's working friction joint as inspiration[1], Erin's current implementation (2.2.1) does not allow independent friction components in the FrictionJoint class. In fact this class simply calculates the relative velocity between anchor points and applies a scaled, thresholded impulse in the opposite direction. The fix for this was straightforward, but required changing the FrictionJoint definition to include three new parameters: the friction coefficients in X, Y, and Theta. IMPORTANT: because this joint is now directional, it's important to specify the joints in the right order. The FrictionJoint solver uses the pose of bodyB to compute friction forces (IE it assumes the friction contact is located at anchorB), which means that the correct order for simulating wheels is bodyA=ground, bodyB=wheel.

References
  1. Original friction joint, courtesy MikeRLewis
  2. My original post about the topic
  3. Follow-up post to [2]
  4. http://gamedev.stackexchange.com/questions/23093/creating-sideways-friction-in-a-2d-top-down-racer
  5. http://www.box2d.org/forum/viewtopic.php?f=3&t=3902
  6. http://www.box2d.org/forum/viewtopic.php?f=8&t=3968
  7. http://www.box2d.org/forum/viewtopic.php?f=3&t=7468

Movies

pybox2d top-down-car mod

About me

Pic of me