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?

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?

Think you need to set hingeJoint.motor.freeSpin = false;

do you have angular drag setup in the rigidbody ?

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.)

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.