Select your preferred scripting language. All code snippets will be displayed in this language.
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
CloseThe motor will apply a force up to a maximum force to achieve the target velocity in degrees per second.
The motor tries to reach motor.targetVelocity
angular velocity in degrees per second.
The motor will only be able to reach motor.targetVelocity
, if motor.force
is sufficiently large.
If the joint is spinning faster than motor.targetVelocity
the motor will break.
A negative motor.targetVelocity
will make the motor spin in the opposite direction.
The motor.force
is the maximum torque the motor can exert. If it is zero the motor is disabled.
The motor will brake when it is spinning faster than motor.targetVelocity
only, if motor.freeSpin
is false.
If motor.freeSpin
is true the motor will not brake.
function Start() { var hinge = GetComponent.<HingeJoint>(); // Make the hinge motor rotate with 90 degrees per second and a strong force. var motor = hinge.motor; motor.force = 100; motor.targetVelocity = 90; motor.freeSpin = false; hinge.motor = motor; }
using UnityEngine; using System.Collections;
public class ExampleClass : MonoBehaviour { void Start() { HingeJoint hinge = GetComponent<HingeJoint>(); JointMotor motor = hinge.motor; motor.force = 100; motor.targetVelocity = 90; motor.freeSpin = false; hinge.motor = motor; } }
Modifying the motor automatically enables the motor by setting HingeJoint.useMotor to true.