Version: 5.4 beta (switch to 5.3)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

HingeJoint.motor

Suggest a change

Success!

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.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public var motor: JointMotor;
public JointMotor motor;

Description

The motor will apply a force up to a maximum force to achieve the target velocity in degrees per second.

The motor tries to reach JointMotor.targetVelocity angular velocity in degrees per second. The motor will only be able to reach targetVelocity, if JointMotor.force is sufficiently large. If the joint is spinning faster than targetVelocity the motor will break. A negative targetVelocity will make the motor spin in the opposite direction.

The 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 targetVelocity only, if JointMotor.freeSpin is false. If freeSpin is true the motor will not brake.

See Also: useMotor, JointMotor.

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;
	hinge.useMotor = true;
}
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; hinge.useMotor = true; } }

Modifying the motor does not automatically enable the motor.

Enabling the motor overrides the spring, given the spring was enabled. If the motor is again disabled the spring will be restored.