Hi, I'm trying to get running a bicicle, but when I execute the simulation, it explodes! That's what I got:
What I'm missing? 😢
Code:
b2BoxDef caja; //Box attaching the wheels
caja.extents.Set(30.0f, 5.0f);
caja.density = 1.0f;
caja.friction = 1.0f;
b2CircleDef circle1, circle2; //the wheels
circle1.radius = 10.0;
circle1.density = 1.0;
circle1.friction = 1.5;
circle1.restitution = 0.1;
circle2.radius = 10.0;
circle2.density = 1.0;
circle2.friction = 1.5;
circle2.restitution = 0.1;
b2BodyDef cuadro;
b2BodyDef rueda1;
b2BodyDef rueda2;
cuadro.AddShape(&caja);
rueda1.AddShape(&circle1);
rueda2.AddShape(&circle2);
cuadro.position.Set(0.0f, 80.0f);
rueda1.position.Set(-20.0f, 80.0f);
rueda2.position.Set(20.0f, 80.0f);
b2Body* bodycuadro = world.CreateBody(&cuadro);
b2Body* bodyrueda1 = world.CreateBody(&rueda1);
b2Body* bodyrueda2 = world.CreateBody(&rueda2);
bodycuadro->AllowSleeping(false);
bodyrueda1->AllowSleeping(false);
bodyrueda2->AllowSleeping(false);
b2RevoluteJointDef jointDefRueda1,jointDefRueda2; //The revolute joins
jointDefRueda1.body1 = bodycuadro;
jointDefRueda1.body2 = bodyrueda1;
jointDefRueda1.collideConnected = false;
jointDefRueda1.anchorPoint = bodyrueda1->GetCenterPosition();
jointDefRueda1.motorTorque = 0.0f;
jointDefRueda1.motorSpeed = 0.0f;
jointDefRueda1.enableMotor = true;
jointDefRueda2.body1 = bodycuadro;
jointDefRueda2.body2 = bodyrueda2;
jointDefRueda2.collideConnected = false;
jointDefRueda2.anchorPoint = bodyrueda2->GetCenterPosition();
b2Joint* joint2 = world.CreateJoint(&jointDefRueda2);
b2Joint* joint1 = world.CreateJoint(&jointDefRueda1);
caja.extents.Set(30.0f, 5.0f);
caja.density = 1.0f;
caja.friction = 1.0f;
b2CircleDef circle1, circle2; //the wheels
circle1.radius = 10.0;
circle1.density = 1.0;
circle1.friction = 1.5;
circle1.restitution = 0.1;
circle2.radius = 10.0;
circle2.density = 1.0;
circle2.friction = 1.5;
circle2.restitution = 0.1;
b2BodyDef cuadro;
b2BodyDef rueda1;
b2BodyDef rueda2;
cuadro.AddShape(&caja);
rueda1.AddShape(&circle1);
rueda2.AddShape(&circle2);
cuadro.position.Set(0.0f, 80.0f);
rueda1.position.Set(-20.0f, 80.0f);
rueda2.position.Set(20.0f, 80.0f);
b2Body* bodycuadro = world.CreateBody(&cuadro);
b2Body* bodyrueda1 = world.CreateBody(&rueda1);
b2Body* bodyrueda2 = world.CreateBody(&rueda2);
bodycuadro->AllowSleeping(false);
bodyrueda1->AllowSleeping(false);
bodyrueda2->AllowSleeping(false);
b2RevoluteJointDef jointDefRueda1,jointDefRueda2; //The revolute joins
jointDefRueda1.body1 = bodycuadro;
jointDefRueda1.body2 = bodyrueda1;
jointDefRueda1.collideConnected = false;
jointDefRueda1.anchorPoint = bodyrueda1->GetCenterPosition();
jointDefRueda1.motorTorque = 0.0f;
jointDefRueda1.motorSpeed = 0.0f;
jointDefRueda1.enableMotor = true;
jointDefRueda2.body1 = bodycuadro;
jointDefRueda2.body2 = bodyrueda2;
jointDefRueda2.collideConnected = false;
jointDefRueda2.anchorPoint = bodyrueda2->GetCenterPosition();
b2Joint* joint2 = world.CreateJoint(&jointDefRueda2);
b2Joint* joint1 = world.CreateJoint(&jointDefRueda1);
What I'm missing? 😢