Simple body hanging in two ropes

Official forum for the Chipmunk2D Physics Library.

Simple body hanging in two ropes

Postby ganesha » Tue Jan 20, 2015 4:26 pm

I am trying to create a simple body hanging in two ropes. I have tried both ChipmunkPivotJoint, ChipmunkPinJoint and ChipmunkDampedSpring but it doesn´t work. I would really appreciate some input about what I am doing wrong.

Pseudo code
Code: Select all

   ChipmunkBody *newBody = [ChipmunkBody bodyWithMass:10.0f andMoment:cpMomentForBox(10.0f, width, height)];
   newBody.position =  startPointArg;

        // Create the joints (assumes default center of mass in the middle)
   CGPoint jointPos1 = CGPointMake(newBody.position.x - width*0.45f, newBody.position.y + ropeLength);
   CGPoint jointPos1_2 = CGPointMake(newBody.position.x - width*0.45f, newBody.position.y);

   CGPoint jointPos2 = CGPointMake(newBody.position.x + width*0.45f, newBody.position.y + ropeLength);
   CGPoint jointPos2_2 = CGPointMake(newBody.position.x + width*0.45f, newBody.position.y);

   self.joint1 = [ChipmunkPinJoint pinJointWithBodyA:[ChipmunkBody staticBody] bodyB:newBody anchorA:jointPos1 anchorB: jointPos1_2];
   self.joint1.maxForce = INFINITY; self.joint1.maxBias = INFINITY;
   self.joint2 = [ChipmunkPinJoint pinJointWithBodyA:[ChipmunkBody staticBody] bodyB:newBody anchorA:jointPos2 anchorB: jointPos2_2];
   self.joint2.maxForce = INFINITY; self.joint2.maxBias = INFINITY;

   // Add joints and body to space etc.
Rectangle with 4 joints and two "ropes". The joints can rotate 360 degrees.
joints.jpg (6.79 KiB) Viewed 1865 times
Posts: 71
Joined: Mon Sep 06, 2010 1:29 pm

Re: Simple body hanging in two ropes

Postby ganesha » Thu Jan 22, 2015 3:25 pm

Looks like a bug calculating the distance between the points for the joints.

I calculate the distance to double check with this formula:
float distance = abs(ccpDistance(jointPos1, jointPos1_2));

distance = ropeLength OK!

When I check the calculated distance:
joint1.dist = 518.0f which is outside the screen!

If I use the set method it doesn´t effect the distance between the joints.
Posts: 71
Joined: Mon Sep 06, 2010 1:29 pm

Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 1 guest