返回介绍

Transform.rotation 旋转角度

发布于 2019-12-18 15:38:41 字数 2097 浏览 1208 评论 0 收藏 0

JavaScript => var rotation: Quaternion;
C# =>

Description 描述

The rotation of the transform in world space stored as a Quaternion.

变换的旋转,在世界坐标空间储存为四元数。

Unity stores rotations as Quaternions internally. To rotate an object, use Transform.Rotate. Use Transform.eulerAngles for setting the rotation as euler angles.

Unity以四元数储存旋转角度。要旋转一个对象使用Transform.Rotate,使用Transform.eulerAngles以欧拉角设置旋转角度。

JavaScript:

	// Reset the world rotation
	transform.rotation = Quaternion.identity;

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    void Example() {
        transform.rotation = Quaternion.identity;
    }
}

另一个例子:

JavaScript:

	// Smoothly tilts a transform towards a target rotation.
	var smooth = 2.0;
	var tiltAngle = 30.0;
	function Update () {
		var tiltAroundZ = Input.GetAxis("Horizontal") * tiltAngle;
		var tiltAroundX = Input.GetAxis("Vertical") * tiltAngle;
		var target = Quaternion.Euler (tiltAroundX, 0, tiltAroundZ);
		// Dampen towards the target rotation
		transform.rotation = Quaternion.Slerp(transform.rotation, target,
		                               Time.deltaTime * smooth);;
	}

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    public float smooth = 2.0F;
    public float tiltAngle = 30.0F;
    void Update() {
        float tiltAroundZ = Input.GetAxis("Horizontal") * tiltAngle;
        float tiltAroundX = Input.GetAxis("Vertical") * tiltAngle;
        Quaternion target = Quaternion.Euler(tiltAroundX, 0, tiltAroundZ);
        transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
    }
}

Transform

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

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

发布评论

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