Maximum distance joint

Well I have spent quite a bit of time on this now and have come to some conclusions.

My character needs to grab hold of things, so I wanted a 'max-distance' joint between the shoulder and arm. For grabbing something solid (eg. ladder), it was ok to use a pulley joint because the hand position would never move. By making the other side of the pulley immovable, it becomes a max-distance joint. This required a little fiddling with the Box2d code to accept an immovable object for one side of the pulley. For grabbing something movable (eg. crate, chair), this one-sided pulley idea would not work so I tried the revolute+prismatic+revolute as suggested here. This mostly worked ok but the connection was very spring-like and did not ever seem to settle into a stable state. This could be because of the number of joints between was larger, or because my character's mass was much greater than the 'pin' bodies holding the revolute and prismatic together. Either way, it wasn't really looking very good.

Then I found a really simple way to do it. Before every world step I check the distance between hand and shoulder. If they are too far apart and not joined, I make a normal distance joint between. If they are close enough and joined, I destroy the joint between them. Believe it or not it works quite well, it even worked well enough that I stopped using the pulley idea for non-movable grab points and used this method instead.

When creating the joint, you need to temporarily move one of the bodies so that the distance between anchor points is the right length, create the joint, then move the body back.

For persistent 'max-distance' joints where one side is always non-movable (eg. chandelier hanging from ceiling) I think the pulley idea is still better because there is no over head with making/breaking joints, and it allows for sleeping when nothing is happening. But since there is only one player actor, who is only sometimes joined to other objects, and will never be sleeping anyway, I figure the extra work of making/breaking joints for his arm in these cases shouldn't be too much of a problem.

Here is an example which fits into the testbed. I didn't think it would work very well on long chains but it's... not too bad.
Sorry to drag up an old post but I wanted to comment on the video, nice concept! Well implemented too. It looks more fun than a lot of games I've played, and it doesn't even have gameplay yet. Keep us posted. Watching that I was thinking of how many different kinds of games it could be. Building defenses, throwing objects at enemies, building solutions to puzzles, doing "stunts"... lots of fun applications.

Thanks for the joint ideas too. I'm working on an overhead action-rpg and I need to keep the "feet" from moving too far from the body, sounds like a pulleyJoint or a sometimes-distanceJoint is what I need.
Thanks. I decided that moving the arm around was too complex, so I will revert to a more typical method where the character simply holds the object in front of them.
I am thinking to make a game like DukeNukem, but instead of just getting to the end of a level, it would have more varied missions with objectives, like GTA3. I put up another vid recently showing the newly implemented water and shooting.
I know I'm resurrecting an old thread, but since a lot of people seemed interested in a max-distance joint, I figured I would shared my hacked version of b2DistanceJoint. Just turn off enforceMinDistance in the def struct. Seems to work OK even when anchors are off-center. The most noticeable problem is that you might get some ringing if you push it really hard beyond the max distance.

Hope that helps someone.
Yep, helped me! cheers!

EDIT: Any idea why I would see objects "sticking" at the critical length? I have a body which flings out and then bounces back elastically (using ApplyForce) with your maximum distance joint connecting them. Rather than just hitting the edge and bouncing, the projectile seems to momentarily stick on the circle, as if a normal distance joint.

I'm guessing it has something to do with the calculation of m_longerThanLength, but I've tried fiddling and I'm not getting anywhere.

Original thread: https://box2d.org/forum/viewtopic.php?t=1098