Getting dampingRatio to work with Box2D and DistanceJoint

221 Views Asked by At

I have tried unsuccessfully on several projects to get a distance joint to stop swinging forever in Box2D for JavaScript. No matter what values I set for the density of the bodies and the dampingRatio and frequencyHz of the distant joint definition - the result is you pick up one end and the other end swings endlessly. I want the swing to get smaller and then stop after a few swings.

// I have made a world and bodies with density of 1 (although I have tried bigger)
var distanceJointDef = new b2DistanceJointDef();
distanceJointDef.Initialize(circleBody, triBody, circleBody.GetWorldCenter(), triBody.GetWorldCenter());
distanceJointDef.dampingRatio = 1; // tried .5, 20, etc. no difference
distanceJointDef.frequencyHz = 30; // tried all sorts of numbers
world.CreateJoint(distanceJointDef);

The joint works - but the damping does not. Any help would be appreciated. Here is a link to the Box2D I am using: https://github.com/joelgwebber/bench2d/tree/master/js/Box2dWeb-2.1a.3

1

There are 1 best solutions below

0
On BEST ANSWER

The answer is to put linear damping on the objects you are swinging. var definition = new b2BodyDef(); definition.linearDamping = .5; // etc. where numbers towards 1 slow quickly