Legacy Documentation: Version 4.6(go to latest)
Language: English
  • C#
  • JS
  • Boo

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;
public motor as JointMotor

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

	// Make the hinge motor rotate with 90 degrees per second and a strong force.

hingeJoint.motor.force = 100; hingeJoint.motor.targetVelocity = 90; hingeJoint.motor.freeSpin = false;
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void Example() {
        hingeJoint.motor.force = 100;
        hingeJoint.motor.targetVelocity = 90;
        hingeJoint.motor.freeSpin = false;
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	def Example() as void:
		hingeJoint.motor.force = 100
		hingeJoint.motor.targetVelocity = 90
		hingeJoint.motor.freeSpin = false

Modifying the motor automatically enables the motor by setting HingeJoint.useMotor to true.