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