Question

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

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top