Anchoring objects relative to each other

So, I’m making a game where you can anchor objects positions relative to each other.

so for instance, if a the box you anchored to a cylinder wants to fall down because of gravity, but the cylinder is resting on the ground, the box cannot fall because of the cylinder. Or if the box is being pushed but the cylinder is on the wall the box cannot be pushed because of the cylinder.

Are there any good ways of doing that? I’ve tried deleting one of the object’s rigidbody and making it a child of the other, but then the Physics.Raycast I use to detect the objects breaks because of it now being one combined object with one rigidbody. Are there any ways to detect one collider from another?

With physics, the solution to couple objects together is called “joints”. Which joint you need and how to configure it is another matter however. If it’s your first time working with joints, expect them not to behave at all the way you want them to. That’s normal. :wink:

Ie a “fixed joint” despite its name will not perfectly keep both objects at the same distance and relative position at all times. There’s always some amount of flexibility involved.

And too much forces and self-intersecting with collisions can explode the objects into outer space.

That worked even better than I hoped, thank you!