breaking 2 bodies from a joint based off stress generated

There's no "feature" for this. But it is easy enough to do for yourself:
Check the joints GetReactionForce() each frame, and decide when it is large enough to break the joint. If it is, remove the joint.
I'm toying with breakable bridges in my platformer engine (using JBox2d), but I've got some problems with them. I create the bridge quite like in the bridge testbed demo. After world.simulate(), I loop over the bridge joints and monitor the joint.getReactionForce. If its length is greater than some value X, I remove the joint, thus breaking the bridge.
Attachment:
bridgetests.jpg
bridgetests.jpg [ 61.15 KiB | Viewed 856 times ]

This seems to work reasonably well, however there's one problem. I noticed that the joint reaction forces grow larger and larger, even when there's nothing on the bridge. At some point the growth stops (actually the bodies might go to sleep, haven't checked that yet). When the player then steps on the bridge, it breaks very easily. Somehow the joint forces build up and cause the brige break more easily the longer it has existed. The effect is even worse when the player rests on the bridge. Although everything is visually very stable, the bodies don't go asleep and the force keeps building up, finally breaking the bridge.

What could cause this kind of behaviour, and how could I stop the bridges getting weaker (i.e. the forces getting bigger) over time? IMHO the bridge shouldn't break by itself when the player rests over it, only after he jumps on to the bridge from altitude etc.

My bridge planks are 1.0 units of width, 0.22 of height with density of 2.0 units, if that matters.
In this case the bridge will have infinite tension when it is perfectly flat. The solver is converging towards a large tension to try to make the bridge flat.

Try giving the bridge some slack (use local anchors for the ground points that are closer than the length of the bridge).
Erin Catto wrote:
In this case the bridge will have infinite tension when it is perfectly flat. The solver is converging towards a large tension to try to make the bridge flat.

While this makes sense...

Quote:
Try giving the bridge some slack (use local anchors for the ground points that are closer than the length of the bridge).

I don't quite follow you here. Could you please elaborate, what do you mean by local anchors for the ground points? I have connected the both ends to the static world body where my whole level geometry resides. The bridge is somewhat far from the world origin, and when I'm in debug draw the joints from the bridge ends go to the world origin. Does the bridge distance from the world origin matter somehow? I would assume not but I'm now a bit confused.. 😳
I'll put it another way. You can't use b2RevoluteJointDef::Initialize on one of your ground anchors.

Let's assume you create the bridge as a horizontal row of planks and the right side terminates at point (xr, yr). You want the ground anchor to be at (xr - offset, yr). You accomplish this by setting the local anchors directly in the joint definition. For example:

def.localAnchor1.Set(xr - offset, yr); // ground
def.localAnchor2.Set(0.5f * width, 0.0f); // plank

This should make the distance between the ground anchors less than the length of the bridge, giving it some slack.

This should reduce the tension in the bridge, but it make not cure your problem completely. But it is worth trying.
Great, I got it working. Thanks Erin! 🙂

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