Prismatic Joint Doubts and Issues

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.


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!!
You can use GetJointTranslation to find out how far apart the joint anchors are along the axis. If the value returned is at or outside the lower/upper translation limits you set, then the joint has reached one of it's limits.
Woow great, thanks a lot.

Any ideas about the sink issue?, I was reading something about set the bodyA as a bullet, but that doesnt work for me?

and finding the cause of this, i found it was caused by the frame simulation rate to fall enough to make the bodies behave like that.

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