Unity 6.3
0 онлайн 21 гостей 3 в системе
Вход

Transform.rotation

Declaration

public Quaternion rotation;

Описание

Quaternion, который хранит вращение Transform в мировом пространстве.

Transform.rotation хранит Quaternion. Вы можете использовать rotation для поворота GameObject или указать текущее вращение. Не пытайтесь редактировать/модифицировать rotation. Transform.rotation меньше 180 градусов.

Transform.rotation не имеет блокировки гимбала.

Для поворота Transform, используйте Transform.Rotate, который использует Эйлеровы углы.

Если вы хотите сопоставить значения, которые вы видите в Inspector, используйте свойство Quaternion.eulerAngles на возвращаемом Quaternion.

using UnityEngine;

// Transform.rotation example.

// Rotate a GameObject using a Quaternion. // Tilt the cube using the arrow keys. When the arrow keys are released // the cube will be rotated back to the center using Slerp.

public class ExampleScript : MonoBehaviour { float smooth = 5.0f; float tiltAngle = 60.0f;

void Update() { // Smoothly tilts a transform towards a target rotation. float tiltAroundZ = Input.GetAxis("Horizontal") * tiltAngle; float tiltAroundX = Input.GetAxis("Vertical") * tiltAngle;

// Rotate the cube by converting the angles into a quaternion. Quaternion target = Quaternion.Euler(tiltAroundX, 0, tiltAroundZ);

// Dampen towards the target rotation transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth); } }

В вышеприведённом примере rotation описаны кватернионом. Более подробно см. Вращение и ориентация в Unity.