Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having some difficulties with Box2D DistanceJoints, I'm trying to create a rope using DistanceJoints connecting some bodies together but the length of joints between bodies change due to weight of bodies, is there any way to prevent joint lengths from changing?

share|improve this question

DistanceJoints can be soft spring like joints, or rigid and firm joints depending on your choice of frequencyHz and dampingRatio.

Set dampingRatio to 1.0 for zero oscillations (i.e. inflexible distance).

You may need to set frequencyHz to 0 as well.

share|improve this answer
I tried changing damping ratio and/ir frequencyHz to any valu that i could imagine, including the onces you suggested but didn't help at all. – Ali.S Jun 2 '11 at 22:34
What are the masses of the two objects that are joined? – Olhovsky Jun 2 '11 at 22:35
at first they were both 1 (due to default density of fixtures) but then tried changing density to zero (the masses were still 1 because objects were dynamic) and it was same as before, no changes. – Ali.S Jun 2 '11 at 22:38
So let me just confirm that density of both objects is set to 1. The mass of both dynamic objects is 1, and the dampingRatio of the DistanceJoint is 1, and the frequencyHz is 0. And in this configuration, your distance joint expands and contracts? – Olhovsky Jun 2 '11 at 22:55
that's right, i can even post my code here if you like' – Ali.S Jun 2 '11 at 22:59

I've faced the same problem, and what I've done was using DistanceJoint, with the frequencyHz set to 60 (or more) and the dampingRatio set to 0.

Imagine your distanceJoint as a rubber thread.

  • Higher frequencyHz makes thread more persistent.

  • Lower dampingRatio make it sooner for the thread gain original length after being stretched.

share|improve this answer
up vote 2 down vote accepted

For those who may encounter this problem in the future: I just changed my approach, I used some Revolute Joint to connect bodies together and mark all bodies as sensor so that they don't collide with each other (tell me if you any better way to avoid collision of the rope parts), and use boxes to fill the space between joints (previously it was Distance joints connecting circle shapes). Having density set to non-zero value the result looks like a real rope.

share|improve this answer
RevoluteJoints and DistanceJoints serve different purposes. Select the one that suits you. If you want to have non-oscillating/firm distances between objects, you can see my answer about DistanceJoints. – Olhovsky Jun 2 '11 at 21:35
(Their difference is described here – Olhovsky Jun 2 '11 at 21:47
I know that, but in my case a fixture and two revoluteJoints produces better results than a DistanceJoint; – Ali.S Jun 2 '11 at 22:36
No worries, +1 since this answer works for you. – Olhovsky Jun 2 '11 at 22:59
For those who read this, set "collideConnect" to "false" in the joint definition avoids fixtures contact. – TechNyquist Jul 5 at 13:11

I was struggling with ropes in Box2D until I discovered that a joint's "strength" is proportional to the mass of the bodies it is connected to. The solution that worked for me was just to increase the density of the rope until it was strong enough to hold other objects up.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.