Hi, im new here, but i started to use box2d for a while.
i´m making a personal project in which i have to use prismatic joints, the thing is, that i don´t know how to detect when the joint has reached its limit, when applying a force to bodyB, i have to mention that when impulsing the bodyB forward, i set bodyA to static and when is back to dynamic.
The solution i made was, when the bodyB, collide with one of the world container borders, apply a force to return it to bodyA. But i wanna know if i cant detect what i said above.
Other thing is, sometimes, when bodyB return to bodyA, bodyA sinks in to the floor which is one of the world container borders. How can i prevent this behavior?
I attach the code to create the joint, as well the code to impulse back and forward the bodyB.
//Create the Joint
prismaticJointDef.Initialize(cBody.body, cTongue.body, cBody.body->GetWorldCenter(), AXIS);
prismaticJointDef.lowerTranslation=0.0f;
prismaticJointDef.upperTranslation=12.0f;
prismaticJointDef.enableLimit=true;
prismaticJointDef.maxMotorForce=1.0f;
prismaticJointDef.motorSpeed=0.0;
prismaticJointDef.enableMotor=true;
prismaticJointDef.collideConnected=true;
prismaticJoint=(b2PrismaticJoint*)world->CreateJoint(&prismaticJointDef);
//Impulse the Body forward
float force=prismaticJointDef.bodyB->GetMass()*100;
prismaticJointDef.bodyA->SetType(b2_staticBody);
prismaticJointDef.bodyB->ApplyForce(b2Vec2(force,0.9), prismaticJointDef.bodyB->GetWorldCenter());
//Impulse the body back
prismaticJointDef.bodyB->ApplyForce(b2Vec2(-prismaticJointDef.bodyB->GetMass()*75,-0.9), prismaticJointDef.bodyB->GetWorldCenter());
Thanks in advance, i would appreciate your help.
See ya!!
i´m making a personal project in which i have to use prismatic joints, the thing is, that i don´t know how to detect when the joint has reached its limit, when applying a force to bodyB, i have to mention that when impulsing the bodyB forward, i set bodyA to static and when is back to dynamic.
The solution i made was, when the bodyB, collide with one of the world container borders, apply a force to return it to bodyA. But i wanna know if i cant detect what i said above.
Other thing is, sometimes, when bodyB return to bodyA, bodyA sinks in to the floor which is one of the world container borders. How can i prevent this behavior?
I attach the code to create the joint, as well the code to impulse back and forward the bodyB.
Code:
//Create the Joint
prismaticJointDef.Initialize(cBody.body, cTongue.body, cBody.body->GetWorldCenter(), AXIS);
prismaticJointDef.lowerTranslation=0.0f;
prismaticJointDef.upperTranslation=12.0f;
prismaticJointDef.enableLimit=true;
prismaticJointDef.maxMotorForce=1.0f;
prismaticJointDef.motorSpeed=0.0;
prismaticJointDef.enableMotor=true;
prismaticJointDef.collideConnected=true;
prismaticJoint=(b2PrismaticJoint*)world->CreateJoint(&prismaticJointDef);
//Impulse the Body forward
float force=prismaticJointDef.bodyB->GetMass()*100;
prismaticJointDef.bodyA->SetType(b2_staticBody);
prismaticJointDef.bodyB->ApplyForce(b2Vec2(force,0.9), prismaticJointDef.bodyB->GetWorldCenter());
//Impulse the body back
prismaticJointDef.bodyB->ApplyForce(b2Vec2(-prismaticJointDef.bodyB->GetMass()*75,-0.9), prismaticJointDef.bodyB->GetWorldCenter());
Thanks in advance, i would appreciate your help.
See ya!!