- Home /
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.
I'm thinking perhaps ConfigurableJoint.targetPosition is where it'll reset to, so I need to figure out how to make the current position the targetPosition..
ConfigurableJoint.targetPosition doesn't seem to control where locked joints default to... :(
I would like an answer for this as well. The targetPosition is only used for the drive/motors. I imagine there is a way to do this...? Or can we just destroy/create the joint? That seems like a sub-optimal way of doing things...
Answer by Jean-Fabre · Jan 26, 2011 at 05:48 AM
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
@$$anonymous$$ Fabre : I am able to compute the euler angles of the configurable joint, and I want to lock it in place with the current angles rather than add a fixed joint, later to be destroyed. You mention in your post above there is a way to do this:
"the solution is to compute the actual current position manually ... then you'll be able to "lock" in place safely and reliably"
Could you explain?
@$$anonymous$$raptor
I have distributed a working solution as a small package on my excavator thread ( Unity 4 only for now, waiting for Unity 5 fixes for proper port...) , here is a direct link.
Basically, you set the TargetRotation property when the joint is at rest, or when you drive it, you use TargetAngularVelocity
Bye,
$$anonymous$$
Answer by JTown · Jan 27, 2011 at 06:32 AM
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.
Answer by stevesan · Aug 22, 2011 at 11:47 AM
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?)...
Answer by SuperUltraHyper · Oct 12, 2017 at 11:52 AM
I just: rididBody.freezeRotation = true;
then false is when I want it to rotate.