How to link objects via joints so they move and rotate together in the Physics Engine, but also move and rotate them independently in a Script?

At it’s most simple, I’m trying to connect object 3 to object 1 in the physics engine. They they move and rotate together, like if you connect them with a Fixed Joint. And most importantly: if object 3 is too heavy, or if it is holding something heavy, I want the whole thing to tip over.

But via script, I want to be able to rotate object 2 (as a joint in the “arm”) in order to get the object 3 to point in a different direction.

I was able to get the desired effect with the Physics Engine by connecting object 3 to object 1 via a Fixed Joint. But when I try to rotate Object 2, Object 3 snaps back in place.

I tried connecting Object 1 to Object 2 via Fixed Joint, and Object 2 to Object 3 via Fixed Joint, simultaneously, but then I couldn’t rotate Object 2 at all.

I think what I’m looking for is a way to link rotation & movement via the physics engine (like what joints do), but allow movement via script.

Is there some way to rotate the joint’s anchor maybe? I couldn’t find anything in the documentation.

Edited for clarity

Physically you only need two objects. You can add a hinge joint to object 1 and offset its anchor point to where you currently have object 2. You then connect the hinge to the arm and and lift the arm by setting the motor target velocity on the hinge. Make sure object 1 is heavy enough to counter the arm’s weight. You may need to add a base/stand child object to object 1 to help prevent it from tipping over too easily.

As the name implies, that joint is “fixed”. It is not meant to rotate connected objects but hold them in place.

Use an appropriate joint for the use case and it’ll work much better (as suggested, the hinge joint would be the first choice here).

If you’re doing robotics, and especially if you’re dealing with heavy stuff vs light stuff, you might want to try ArticulationBody joints. The RevoluteJoint type is what you want, to rotate about a single axis like that (I found it much easier to set up than a “normal” Rigidbody joint).
To do the rotation, you set the rotation target & max force & stuff and it’ll drive the arm to that position for you.
ArticulationBody hierarchies don’t like being enabled/disabled or having joints added or removed, so bear this in mind in case it’s a dealbreaker for you (you can work around this stuff, but it’s awkward).

I looked into those, but the thing is, I want the joint to act like a Fixed Joint for the Physics System. I only want to rotate the joints via script.

I didn’t see a way “lock” the joints for the physics engine when I looked at other joint types.

Thank you for the heads up! I was in the process of testing out ArticulationBody Joints, but swapping out the pieces of the robot arm is the core gameplay mechanic. I’ll toss that idea in the bin.

It’s doable, just needs some care.
Iirc you need to cache all the joint positions and forces and stuff, make your change to the hierarchy, and then restore the cache, cos any changes to the hierarchy reset the joint states.
I cheat, leave my hierarchy intact but set my colliders to be triggers and turn off the visual meshes😁.
I really like the ArticultionJoint stuff.