Modify distance joint length at runtime

Discuss issues specific to using Box2D on the iPhone
abdulthegamer
Posts: 2
Joined: Wed Jun 12, 2013 7:51 am

Modify distance joint length at runtime

Postby abdulthegamer » Sat Jul 13, 2013 1:50 am

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...

pTymN
Posts: 518
Joined: Tue Sep 25, 2007 2:22 pm

Re: Modify distance joint length at runtime

Postby pTymN » Mon Jul 15, 2013 6:36 am

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");
   }
}


Return to “iPhone”



Who is online

Users browsing this forum: No registered users and 1 guest