In script, how to set ConfigurableJointMotion to locked without it reseting to default position

I need to set ConfigurableJointMotion to locked for one frame, but when it locks it resets the position to the default position -- is there any way I can have it lock to the current position instead? For extra clarification, it goes Limited>Locked>Limited.

Hi,

You can't lock and expect the joint to stay in its current state unfortunately ( very, very unfortunate actually...), the solution is to compute the actual current position manually ( yes, another very unfortunate miss...), then you'll be able to "lock" in place safely and reliably.

Computing the current position is very dependent on your rig, so it's difficult ( at least for me...) to give you a scripted answer to your problem, if you can share a project, then I can definitely look at it.

You can see an example of this with an excavator simulation where all arms joint goes from limited to "lock" back and forth following user's inputs.

Bye,

Jean

I think I found a decent solution myself. I leave the existing joints alone, but add a fixed joint for the frame I apply force (then destroy the fixed joints). I still need to tweak everything though... it seems like I might have to apply torque across multiple frames to get what I want.

OK I just tried something crude, but it seems to work quite alright: When you want to lock things in place relative to each other, destroy the ConfigurableJoint and create a FixedJoint! Then vice versa when you need it to move again. This will require you to modify your calculations so things are relative to the current position, etc., but that’s all doable.

It seems silly that we can’t just modify the “rest position” of the ConfigurableJoint (maybe there is a way?)…

I just:
rididBody.freezeRotation = true;

then false is when I want it to rotate.