Base question: How can I make a swinging rope in box2d?

Context: The idea is to have a rope where the player can grab it, swing a little bit to get more "momentum" and reach the next platform. Like in the Mario games for Nintendo DS and Wii.

What I did: I constructed a chain like rope with a series of RevoluteJoint. This is the fixture of the different links:

fixtureDef.shape = robeLinkShape;
fixtureDef.density = 1.0f;
fixtureDef.friction = 0.0f;
fixtureDef.restitution = 0.0f;
fixtureDef.filter.categoryBits = Box2DConst.BIT_ROPE;
fixtureDef.filter.maskBits = Box2DConst.BIT_PLAYER;

BodyDef bodyDef = new BodyDef();
bodyDef.angularDamping = 1.0f;
bodyDef.linearDamping = 1.0f;

I've implemented a ContactListener which creates a RevoluteJoint to connect the body and on of the links of the body. Now the problem I face is this: The rope does not swing, if I apply a linearImpulse to the player (attached to the rope) e.g. to the left, it goes to the left but it doesn't swing back. If the player isn't attached the rope swings.

Last points:

  • I made the player a dynamic body with a density of 1. Is it better, if the player body does not have a density set?
  • If the chain is to "light" (lower density) the player can torn it apart if he is attached to the rope. If I connect the last link with the first link of the chain with a RopeJoint the last and the first link stay at the same distance but for some reason, the links between still get torn apart. Question is, should I make my rope only of RopeJoins?

I know there are some tutorials out there with some instructions but some of them use a special class which is not available to me and other simply construct a rope and use a MouseJoint. Again in this scenario my rope thing looks good the problem that when the player body is attached to it it behaves a little bit strange. I know there are also similar posts to mine but since I have some sort of a working solution there solution (if the have any) was not helpful.


If I create the rope solely from RopeJoints I get a nice swinging rope. It behaves exaclty as I woulrd expect. If I then a RevoluteJoint with a density (my player body fixture also has a density) the rope does no longer swing.

  • \$\begingroup\$ Possible duplicate: gamedev.stackexchange.com/questions/40104/… \$\endgroup\$
    – House
    Sep 27 '14 at 15:40
  • \$\begingroup\$ Not its not, maybe you didn't read my question or theirs but saidly its not - ohterwise I would have found the answer their... \$\endgroup\$
    – morpheus05
    Sep 27 '14 at 15:52
  • \$\begingroup\$ "If I create the rope solely from RopeJoints I get a nice swinging rope." The why not do this? The fact is RevoluteJoint are simply incapable of handling what you are trying to do with them. Each one tries to resolved the forces upon them individually and you get strange non expected behaviors. If you issue is you character acts unexpected when attached to a rope from RopeJoints you should edit your question to make that more clear. \$\endgroup\$ Sep 28 '14 at 4:16
  • \$\begingroup\$ "Each one tries to resolved the forces upon them individually and you get strange non expected behaviors." I don't quite understand what you mean. The problem is that if the character is attached to the rope you cannot swing. If you push to the left you swing left but you don't get pulled back (if the rope is made with RevoluteJoints) I'm sorry if my question isn't clear enough \$\endgroup\$
    – morpheus05
    Sep 28 '14 at 6:17

Your Answer

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

Browse other questions tagged or ask your own question.