A b2DistanceJoint simply keeps two b2Body at a certain distance from each other at all time but that’s the only freedom restriction those b2Body have. This joint can be used as part of a complex object where you are using many type of joint or for creating chains for example. You can apply many joint type to the same b2Body or group of b2Body so the b2DistanceJoint can really take a good place in your complex object creation. You imagination is the only limit. Click to start:

A very simple example but really the b2DistanceJoint can help you create very complex mechanics and objects. Not much code needed either:

var distance:b2DistanceJointDef = new b2DistanceJointDef();

distance.Initialize(boxtwo, boxthree, new b2Vec2(55 / SCALE, -50 / SCALE) , new b2Vec2(65 / SCALE, -50 / SCALE) )

var disatncejoint:b2DistanceJoint = world.CreateJoint(distance as b2JointDef) as b2DistanceJoint;

You pass the two b2Body you want to link and then two b2Vec2, one representing the first anchor point attached to the first b2Body and the second representing the second anchor point attached to the second b2Body. Let’s move now onto more complex type of joint.