Version: Unity 6.7 Alpha (6000.7)
LanguageEnglish
  • C#

Rigidbody2D.AddTorque

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

Submission failed

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

Close

Cancel

Declaration

public void AddTorque(float torque, ForceMode2D mode = ForceMode2D.Force);

Parameters

Parameter Description
torque Torque to apply.
mode The force mode to use.

Description

Apply a torque at the rigidbody's centre of mass.

Applying torque to the Rigidbody2D changes the Rigidbody2D.angularVelocity only. This change is scaled (divided) by the rotational Rigidbody2D.inertia. Therefore, a larger Rigidbody2D.inertia results in smaller changes to Rigidbody2D.angularVelocity, and a smaller Rigidbody2D.inertia results in larger changes to Rigidbody2D.angularVelocity.

When applying torque either as a force or an impulse, you can use any value to get the required change in Rigidbody2D.angularVelocity. However, if you require a specific change in degrees, then you must first convert the torque value into radians by multiplying with Mathf.Deg2Rad then multiplying by the Rigidbody2D.inertia.

The following example demonstrates this as an impulse:

Additional resources: Rigidbody2D.AddForce, Rigidbody2D.AddForceAtPosition

using UnityEngine;

public class TorqueRotationExample : MonoBehaviour { // Add an impulse which produces a change in angular velocity (specified in degrees). public void AddTorqueImpulse(float angularChangeInDegrees) { var body = GetComponent<Rigidbody2D>(); var impulse = (angularChangeInDegrees * Mathf.Deg2Rad) * body.inertia;

body.AddTorque(impulse, ForceMode2D.Impulse); } }