Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Achieve joint break when more than certain force is applied

I have two dynamic bodies attached together with a revolute joint. Both of the bodies are also connected to a static body on the other ends. I need the joint between the two dynamic bodies to break when more than a certain amount of force is applied, that is, when there's more mass than the joint can resist. How is this done in Box2d? I guess this is not handled by Box2d automatically. Here's the graphical overview of what I want to achieve.

enter image description here

like image 221
Mikayil Abdullayev Avatar asked Feb 25 '13 11:02

Mikayil Abdullayev


1 Answers

Use b2Joint::GetReactionForce.

In each time step check, if reaction force of the joint is less then some critical value. When force became greather, destroy the joint.

void update(float timeStep)
{
    b2Vec2 reactionForce = joint->GetReactionForce(1/timeStep);
    float forceModuleSq = reactionForce.LengthSquared();
    if(forceModuleSq > maxForceSq)
    {
        world->DestroyJoint(joint);
    }
}

world - pointer to b2World, joint - pointer to your b2RevoluteJoint, maxForceSq - square of the max force.

Look, there calculates LengthSquared, and compares with squared maxForce. This will improve performance, because no need to calculate square root.

Max force can be calculated as gravitational force: maxMass*9.8.

like image 52
Pavel Avatar answered Nov 11 '22 21:11

Pavel