- Home /
Rotate a hinge at runtime using script
It looks like you can't set the angle property of a hinge joint - how do you rotate a hinge joint at runtime?
Answer by ina · Dec 26, 2010 at 11:59 AM
transform.RotateAround seems to do the trick!
Next up... is there such a thing as changing the friction field built-into this joint (it's so low, the contraption looks apparently like a perpetual motion machine - it won't stop swinging once in motion!), or must that be done programmatically?
Answer by LS16BMX · Jan 03, 2012 at 11:44 PM
Think you need to set hingeJoint.motor.freeSpin = false;
hmmm i'm still not sure what freespin does - can't seem to get it to do anything
Answer by ChrisBennet · Jan 13, 2013 at 07:09 AM
I enable the spring parameter and change the spring target position so the springs "pull" the hinge to the new position. For example, with spring.TargetPosition = 0 the door would be closed. When I want to open the door I set TargetPosition = 90 (degrees) and the door will swing open.
(I'm not at my computer so I may have the spelling slightly off.)
Answer by KalebGraceTwistory · Feb 03, 2015 at 12:31 AM
Try this:
float angle = 45f;
JointLimits jl = new JointLimits();
jl.min = angle;
jl.max = angle;
hingeJoint.limits = jl;
It seems to work great for me. Note: If you're actually using the limits for the standard purpose, you'll have to cache off the original JointLimits struct and reapply it later.