The fact that I made rope. using b2RopeJoint. but it does not DampingRatio as for example at b2DistanceJoint. How can I add to my rope small damping. Please Help)) I create rope :
void GameScene::createRope(b2Body *bodyA, b2Body *bodyB, b2Vec2 anchorA, b2Vec2 anchorB, float sag)
{
b2RopeJointDef jd;
jd.bodyA = bodyA;
jd.bodyB = bodyB;
jd.localAnchorA = anchorA;
jd.localAnchorB = anchorB;
jd.collideConnected = true;
// Max length of joint = current distance between bodies * sag
float32 ropeLength = (bodyA->GetWorldPoint(anchorA)- bodyB->GetWorldPoint(anchorB)).Length()*sag;
jd.maxLength = ropeLength;
// Create joint
b2RopeJoint* ropeJoint=(b2RopeJoint*) world->CreateJoint(&jd);
VRope *newRope = new VRope(ropeJoint, _ropeSpriteSheet);
_ropes.push_back(newRope);
}
It's not really clear what you mean by damping for the rope, but I'll assume you want the rope to look like it is a little bit stretchy.
You could use a combination of both a distance joint and a rope joint. If you make the distance joint a little shorter than the rope joint, it will tend to slow the pulling object down a little just as the rope nears full extension, and return it to a 'rest' position that is closer than the rope joint limit. You would also need to check if the joint anchors are closer than the length of the distance joint and if so, set the damping of the distance joint to zero, to prevent it from pushing the joined bodies apart.
As an example, suppose the natural length of the rope should be 1, but you want to allow it to stretch to 1.1 when it is pulled by a heavy object. In this case the length of the distance joint would be 1 and the length of the rope joint would be 1.1
To check when the distance joint damping should be set to zero, you could do something like this:
//b2DistanceJoint dj;
float distBetweenAnchors = ( dj.getAnchorA() - dj.getAnchorB() ).Length();
if ( distBetweenAnchors < dj.GetLength() )
dj.SetDampingRatio( 0 );
else
dj.SetDampingRatio( NORMALDAMPING );