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

参数

torque 要施加的扭矩。
mode 要使用的力模式。

描述

在刚体的质心处施加扭矩。

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

When applying torque either as a force or an impulse, you can use any value to get the required change in 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 inertia.

The following example demonstrates this as an impulse:

See Also: AddForce, 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); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961