Custom joints? (Or other workaround.)

Feature I'm wanting to implement: 'clone' objects that are tied to the original.

The sort of thing that gets used in a puzzle game - there are two of you, and you can only move 'north' if both copies are unobstructed. Essentially, the x and y distance between the clones are locked. This could be done with a pair of distance joints, if the objects were unable to rotate.

But I also want the objects to be able to rotate (either independently or also both locked to the same angle, but not around a common central pivot!)

As best as I can tell, what I'm looking for is two additional types of joint - a "relative position" joint and a "relative angle" joint.

I feel like this could maybe be done with a crazy stack of things, like a pair of invisible objects with prismatic x-axis and y-axis joints to a static object, with those prismatic joints being linked together with gear joints, and then a revolute joint on top of each of those objects, with the two revolute joints gear-joined together, and then the actual objects attached to the revolutes. But it also seems like that's a bit of a hideous way to do it (especially if it gets into more than 2 clones), hence the question, is there a way to make custom joints between objects, without modifying the library?

Alternatively, is there a less hideous third way to implement that behavior? Or, another alternative, is the hideous stack of things actually not as bad as I think?
Firstly to restrict their movement to be the same you could pin them both to a fixed-rotation body with revolute joints.

Then to keep their rotation matching you could connect them with a fixed-rotation rod between them, that's just one body and two revolute joints. Destroying and re-creating this would allow them to be freed from the rotation restriction temporarily.

As long as you want the same rotation for all of them I don't think you need such a huge crazy stack of things - perhaps you are just overlooking what fixed-rotation bodies could allow. If you want different ratios of rotation between them that's a different story, you'd probably need to use gear joints...

Judging from this pic, I have a feeling that using more than one set of these all connected together would work fine 🙂
Image
irresistible force wrote:
Firstly to restrict their movement to be the same you could pin them both to a fixed-rotation body with revolute joints.

Ahh, clever. A joining body with no mass. And thanks for the picture that explains what you were saying really simply. Would have taken me much longer to figure out without it!

Edit: I think probably the rotation would be better served with a gear joint anyway though, it seems like resolving that would require a lot less iterating than resolving the battle between sticks and revolutes. Gears are pretty simple once the things are pinned to a non-rotating blank to solve the first problem.

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