[idiot] A chain. Shouldn't be that hard. But somehow it is.

[using 2.1a]
I've followed the examples and a tutorial from Emanuel, and something's just not working.

Here's the result:
Image
As you can see, the joints are "connected" but they don't rotate; instead they separate. No good.

Here's the code that I'm using:
Code:
var fixture:b2Fixture;
var body:b2Body;
var link:b2Body = _body;
var revolute_joint:b2RevoluteJointDef = new b2RevoluteJointDef();
var Y:Number;
var length:Number = Physics.WORLD_SCALE;
var relLength:Number = length / Physics.WORLD_SCALE;
var startY:Number = py + (this.width * 0.45);

md = new b2MassData();
md.mass = 1;
         
for( var i:int = 0; i < 10; i++ )
{
   // rope segment
   Y = startY + (i * length);
   fixture = Physics.instance.createBox(X, Y, 2, length, b2Body.b2_dynamicBody);
   fixture.SetFriction(0.5);
   body = fixture.GetBody();
   body.SetMassData(md);
            
   // joint
   revolute_joint.Initialize( link, body, new b2Vec2( (X + 1) / Physics.WORLD_SCALE, body.GetPosition().y - relLength/2 ) );
   Physics.instance.world.CreateJoint( revolute_joint );
            
   // saving the reference of the last placed link
   link = body;
   _chains.push(body);
}


So, what simple thing am I overlooking that will make this set of boxes work like a chain? Do you need to know my b2World conditions in order to solve this?
if Box2D2.1 still has SetMassByShape you should use that instead of your mass setting. i know in 2.01 rotational inertia was set by the mass settings so perhaps thats not being set correctly on your bodies.

i am otherwise unsure.
As I understand it, you can set the density of fixtures and then use ResetMassData to recalculate the mass based on the density and area. But what would that change? I would simply change the density so that the mass of each segment turned out to be equal to what I'm setting the mass to right now. Unless, is there some byproduct of this process I'm missing?
Do you have "fixedRotation" on for your bodies?
No, and it looks like it's off by default.
It looks like because the density was zero, even though I set the mass later, box2d was treating it as a static object. Huh. 🙂

Original thread: https://box2d.org/forum/viewtopic.php?t=4689