4
\$\begingroup\$

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?

\$\endgroup\$
5
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – Ali1S232 Jun 2 '11 at 22:34
  • \$\begingroup\$ What are the masses of the two objects that are joined? \$\endgroup\$ – Olhovsky Jun 2 '11 at 22:35
  • \$\begingroup\$ 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. \$\endgroup\$ – Ali1S232 Jun 2 '11 at 22:38
  • \$\begingroup\$ 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? \$\endgroup\$ – Olhovsky Jun 2 '11 at 22:55
  • \$\begingroup\$ that's right, i can even post my code here if you like' \$\endgroup\$ – Ali1S232 Jun 2 '11 at 22:59
3
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – Olhovsky Jun 2 '11 at 21:35
  • \$\begingroup\$ (Their difference is described here box2d.org/manual.html.) \$\endgroup\$ – Olhovsky Jun 2 '11 at 21:47
  • \$\begingroup\$ I know that, but in my case a fixture and two revoluteJoints produces better results than a DistanceJoint; \$\endgroup\$ – Ali1S232 Jun 2 '11 at 22:36
  • \$\begingroup\$ No worries, +1 since this answer works for you. \$\endgroup\$ – Olhovsky Jun 2 '11 at 22:59
  • \$\begingroup\$ For those who read this, set "collideConnect" to "false" in the joint definition avoids fixtures contact. \$\endgroup\$ – TechNyquist Jul 5 '16 at 13:11
0
\$\begingroup\$

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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