A b2FrictionJoint lets you apply friction to a b2Body. This can be useful for simulating friction between two pieces of machinery or simply for representing the friction occurring when an object rolls over different type of ground. In this next example all falling basketball have the same size and weight but the ones on the left have a b2FrictionJoint applied to them so you can see the difference in speed and bounciness. Note that once you create a b2FrictionJoint you can of course change on the fly its effect by adjusting its maxForce and maxTorque property. Like if you were creating a mini golf type of game, you could set the maxForce to 0 when passing over ice and to 8 or 9 when passing on grass. Anyway click anywhere to see this joint in action:

With such a high level of friction the basketballs on the left have the tendency to stick easily to other object. You can notice also the speed difference. Here is the relevant code:

var jointdef:b2FrictionJointDef = new b2FrictionJointDef();



jointdef.bodyA = body;

jointdef.bodyB = contacttarget;

jointdef.maxForce = 6;

jointdef.maxTorque = 5;

jointdef.collideConnected = true;

world.CreateJoint(jointdef as b2JointDef);

We set the two anchor point to zero so the friction doesn’t have a direction. We then set the first body as the target of the friction and the second body as the ground (in this example). Then we set some force and torque values and make sure the two bodies can still collide with each other. Let’s now take a look at the b2MouseJoint.