Hooking 2 Objects Together

Hey guys,
I'm creating a building application of sorts, and was hoping someone could provide me with a little advice. It is sort of like an editor, that allows you to take smaller building blocks and hook them together into 2 larger object. The blocks can only hook together on the top and the bottom, i.e kinda like you were building with Legos.

There are a few issues here, but the main one is actually hooking the objects together. Once they snap together, they need to be completely rigid. The only way I could think of to hook them together was a a joint, and i limited the bounds so it couldn't rotate. However when your moving it around, it is very loose and they don't feel like they are actually snapped together.

The next issue is actually figuring out when to snap them together. Currently I am testing for collision. if the angle of each block is roughly the same, and the Y difference of each block is enough so it means one is on top of the other, then the joint is created. The problem is that this doesn't work if the blocks are already rotated, because the y difference won't be enough. Instead of the y difference, I'm guessing I'd have to take the position of the block and extend it out based on the angle using vectors, and then compare that position to the posiiton of the other block. I am ure I could figure this out if I play around with it enough, but any suggestions would be appreciated.

Hopefully this makes sense. Please let me know if you have any input or suggestions.

Thanks,
Sirus
Quote:
Once they snap together, they need to be completely rigid.

Then you want them both to be part of the same Rigid Body, aka b2Body. 😉 Try removing the old bodies, and then making a new body and adding both shapes to it.
Yeah - what shaktool said. You don't have to destroy both bodies though. You can keep one and just add a new shape to it (based off of the body you're destroying).
section 5.4.5 in the manual named "Coordinate Transformations" is your key to comparing positions

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