返回介绍

Rigidbody.AddTorque 添加扭矩

发布于 2019-12-18 15:38:28 字数 3781 浏览 1012 评论 0 收藏 0

JavaScript => public function AddTorque(torque: Vector3, mode: ForceMode = ForceMode.Force): void;
C# => public void AddTorque(Vector3 torque, ForceMode mode = ForceMode.Force);

Parameters 参数

torqueTorque vector in world coordinates.
在世界坐标空间扭矩的向量。

Description 描述

Adds a torque to the rigidbody.

添加扭矩到刚体。

Force can be applied only to an active rigidbody. If a GameObject is inactive, AddTorque has no effect.

力仅应用于激活的刚体。如果游戏对象未激活,添加扭矩无效果。

Wakes up the Rigidbody by default. If the torque size is zero then the Rigidbody will not be woken up.

默认刚体是唤醒的。如果力的大小为0,那么刚体不被唤醒。

See Also: AddRelativeTorque, AddForce.

JavaScript:

// Rotate an object around its Y (upward) axis in response to
// left/right controls.
var torque: float;
var rb: Rigidbody;
 
function Start() {
	rb = GetComponent.<Rigidbody>();
}
 
 
function FixedUpdate() {
	var turn = Input.GetAxis("Horizontal");
	rb.AddTorque(transform.up * torque * turn);
}

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    public float torque;
    public Rigidbody rb;
    void Start() {
        rb = GetComponent<Rigidbody>();
    }
    void FixedUpdate() {
        float turn = Input.GetAxis("Horizontal");
        rb.AddTorque(transform.up * torque * turn);
    }
}

JavaScript => public function AddTorque(x: float, y: float, z: float, mode: ForceMode = ForceMode.Force): void;
C# => public void AddTorque(float x, float y, float z, ForceMode mode = ForceMode.Force);

Parameters 参数

参数描述,换行请使用\\空格
xSize of torque along the world x-axis.
在世界坐标绕x轴的扭矩大小。
ySize of torque along the world y-axis.
在世界坐标绕y轴的扭矩大小。
zSize of torque along the world z-axis.
在世界坐标绕z轴的扭矩大小。

Description 描述

Adds a torque to the rigidbody.

添加扭矩到刚体。

Force can be applied only to an active rigidbody. If a GameObject is inactive, AddTorque has no effect.

力仅应用于激活的刚体。如果游戏对象未激活,添加扭矩无效果。

Wakes up the Rigidbody by default. If the torque size is zero then the Rigidbody will not be woken up.

默认刚体是唤醒的。如果力的大小为0,那么刚体不被唤醒。

Rigidbody

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文