Hi all,
I'm not sure if this is a bug but it's very annoying, if anyone knows a solution or tell me what I'm doing wrong I'd really appreciate it.
I'm setting up two shapes and creating a revolute joint between them. The problem is the second body seems to swing around right after setup. This only happens when I set the angle variable of body1 ( bd.angle = DEGTORAD(65);). If I set everything up without setting the angle body2 does not swing. It's almost like the angle of body1 is not set until after we've started simulating, thus causing body2 to swing. I've checked everything and based on the angles and joint position nothing should be moving unless another body collides with it.
Thanks for the help! 🙂
I'm not sure if this is a bug but it's very annoying, if anyone knows a solution or tell me what I'm doing wrong I'd really appreciate it.
I'm setting up two shapes and creating a revolute joint between them. The problem is the second body seems to swing around right after setup. This only happens when I set the angle variable of body1 ( bd.angle = DEGTORAD(65);). If I set everything up without setting the angle body2 does not swing. It's almost like the angle of body1 is not set until after we've started simulating, thus causing body2 to swing. I've checked everything and based on the angles and joint position nothing should be moving unless another body collides with it.
Thanks for the help! 🙂
Code:
// body 1
sd.density = 30.0f;
sd.friction = 0.2f;
sd.restitution = 0.4f;
sd.SetAsBox(18.60f, 1.10f);
bd.position.Set(38.59f, -61.90f);
bd.angle = DEGTORAD(65);
body1 = wld->world->CreateBody(&bd);
body1->CreateShape(&sd);
body1->SetMassFromShapes();
// body 2
sd.density = 10.01f;
sd.friction = 5.2;
sd.restitution = 0.1;
sd.SetAsBox(5.0f, 5.0f);
bd.position.Set(44.5f, -51.0f);
bd.angle = DEGTORAD(0);
body2 = wld->world->CreateBody(&bd);
body2->CreateShape(&sd);
body2->SetMassFromShapes();
//joint
// joints
b2RevoluteJointDef jointDef;
b2Vec2 pos;
pos = body1->GetPosition();
jointDef.Initialize(body1,body2, b2Vec2(pos.x+6.5,pos.y+16.0));
jointDef.collideConnected = false;
jointDef.enableLimit = false;
joint1 = wld->world->CreateJoint(&jointDef);
sd.density = 30.0f;
sd.friction = 0.2f;
sd.restitution = 0.4f;
sd.SetAsBox(18.60f, 1.10f);
bd.position.Set(38.59f, -61.90f);
bd.angle = DEGTORAD(65);
body1 = wld->world->CreateBody(&bd);
body1->CreateShape(&sd);
body1->SetMassFromShapes();
// body 2
sd.density = 10.01f;
sd.friction = 5.2;
sd.restitution = 0.1;
sd.SetAsBox(5.0f, 5.0f);
bd.position.Set(44.5f, -51.0f);
bd.angle = DEGTORAD(0);
body2 = wld->world->CreateBody(&bd);
body2->CreateShape(&sd);
body2->SetMassFromShapes();
//joint
// joints
b2RevoluteJointDef jointDef;
b2Vec2 pos;
pos = body1->GetPosition();
jointDef.Initialize(body1,body2, b2Vec2(pos.x+6.5,pos.y+16.0));
jointDef.collideConnected = false;
jointDef.enableLimit = false;
joint1 = wld->world->CreateJoint(&jointDef);