Modify distance joint length at runtime

hi,

I have created a distance joint between two bodies ....
Now i want to increase or decrease length of distance joint at runtime without destroying the present joint...

is it possible ...
Please Help...

Code: Select all

void Rope::changeLength(TSFloat lengthDelta) {
   RopeJoint& currentRopeJoint = GetRopeJoint(0);
   TSFloat actualLength = (currentRopeJoint.position - player->body->GetPosition()).Length();
   
   // Find supposed joint length
   if (length == 0.0) {
      length = activeJoint->GetLength();
   }
   
   // Length cannot get more than maxJointTension away from real
   // length, and is bounded by min and max.
   length = b2Clamp(length + lengthDelta,
                    minLength,
                    maxLength - currentRopeJoint.accumulatedLength);
   
   length = b2Clamp(length,
                    actualLength - maxJointTension,
                    actualLength + maxJointTension);
   
   activeJoint->SetLength(length);
   
   if(maxLength - FLT_MIN <= length + currentRopeJoint.accumulatedLength) {
      detach();
      //TS.log("rope is too long, detaching");
   }
}

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