返回介绍

Rigidbody2D.MoveRotation 移动旋转

发布于 2019-12-18 15:38:30 字数 3007 浏览 1376 评论 0 收藏 0

JavaScript => MoveRotation(angle: float): void;
C# => void MoveRotation(float angle);

Parameters 参数

angleThe new rotation angle for the Rigidbody object.
用于刚体对象的新的旋转角度。

Description 描述

Rotates the rigidbody to angle.

旋转该刚体到“angle”。

Rotates the rigidbody to the specified angle by calculating the appropriate angular velocity required to rotate the rigidbody to that angle during the next physics update. During the move, angular drag won't affect the body. This causes the object to rapidly move from the existing angle to the specified angle.

旋转该刚体到指定的angle,通过合适的角速度计算来旋转刚体到指定的角度,该角度在下次物理更新。在旋转期间,角阻力不影响刚体。这使得对象从现有的角度快速移动到“angle”。

Because this feature allows a rigidbody to be rotated rapidly to the specified angle, any colliders attached to the rigidbody will react as expected i.e. they will produce collisions and/or triggers. This also means that if the colliders produce a collision then it will affect the rigidbody movement and potentially stop it from reaching the specified angle during the next physics update. If the rigidbody is kinematic then any collisions won't affect the rigidbody itself and will only affect any other dynamic colliders.

因为这个功能允许刚体通过世界坐标快速旋转到指定的角度,附加到刚体的任何碰撞器正如预期反应;如,产生碰撞或触发。这意味着如果刚体产生碰撞,那么在它到达指定的“angle”下次物理更新期间,将影响刚体旋转或可能停止。如果是运动学刚体,那么任何碰撞不会影响刚体自身,仅影响其他物理碰撞器。

2D rigidbodies have a fixed limit on how fast they can rotate therefore attempting to rotate large angles over short time-scales can result in the rigidbody not reaching the specified angle during the next physics update. It is recommended that you use this for relatively small rotational movements only.

2D刚体有一个固定的限制,它们快速移动,因此在很短的时间试图旋转较大的角度,这导致刚体在下次物理更新期间没能到达指定的“angle”。建议你只在使用相对较小的旋转移动。

It is important to understand that the actual rotation change will only occur during the next physics update therefore calling this method repeatedly without waiting for the next physics update will result in the last call being used. For this reason, it is recommended that it is called during the FixedUpdate callback.

重要的是要了解实际位置变化只发生在下次物理更新,因此,调用这个方法不等待下次物理更新将导致上次调用正在使用。由于这个原因,建议在FixedUpdate回调时调用。

JavaScript:

	private var speed : float = 15;
	function FixedUpdate () {
		rigidbody2D.MoveRotation(rigidbody2D.rotation + speed * Time.deltaTime);
	}

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    private float speed = 15;
    void FixedUpdate() {
        rigidbody2D.MoveRotation(rigidbody2D.rotation + speed * Time.deltaTime);
    }
}

Rigidbody2D

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

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

发布评论

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