Box2D weld joint

So one might think this is the simplest joint, but it turns out there are so much subtlety into it. After a gruesome few days of trying to figure out what went wrong with my weld joint, finally I (think I) get a good grasp of it.

Let's start with the basic:

There are 3 major components with joints.
1. The reference body. This is the body that goes first in the b2JointDef.Initialize method. The reference is the body to which the joint is attached.
2. The target body. This is the body that goes second in the b2JointDef.Initialize method. The target body is the attached body. So the movement of the target body follows that of the reference body.
3. Anchor. Where to attach the target body to the reference body. This is a b2Vec2 coordinate relative to the reference body.

i.e:

b2WeldJointDef.Initialize(refBody, targetBody, b2Vec2(-5, 10));

The target body will be glued to the reference body at -5, 10 from the ref body position.

As for the weld joint, one must define the following for it to work:


    bodyDef.fixedRotation = FALSE;
    fixDef.density = 2.0f;


Basically one must define the density and set fixedRotation to false. Otherwise, the weld joint will fall off. The bodies glued together using weld joint must also be large enough. There will be an area check somewhere inside the Box2D engine to make sure that areas joined exceed a certain delta value!

0 komentar:

Posting Komentar