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

Quaternion.SetLookRotation

Declaration

public void SetLookRotation(Vector3 view, Vector3 up = Vector3.up);

Параметры

Параметр Описание
вид Направление, в котором нужно смотреть.
вверх Вектор, определяющий, в каком направлении находится вершина.

Описание

Создает вращение с указанными направлениями forward и upwards.

Изменяет текущий кватернион, чтобы он имел указанный forward и upwards направления.

Этот метод обновляет существующий кватернион на месте, в отличие от Quaternion.LookRotation если используется для ориентации Transform, ось Z выравнивается с осью forward вектора направления и оси Y с upwards направление вектора, предполагая, что эти векторы ортогональны. Записывает ошибку, если направление вперед равно нулю.

Дополнительные ресурсы: LookRotation.

using UnityEngine;

// This example demonstrates the SetLookRotation method, // and describes its key difference from the LookRotation method. public class Quaternions : MonoBehaviour { void Start() { Vector3 direction = Vector3.right;

// Method 1: LookRotation - a static method that created a new quaternion Quaternion newRotation = Quaternion.LookRotation(direction); Debug.Log($"LookRotation creates new: {newRotation}");

// Method 2: SetLookRotation - an instance method that modifies an existing quaternion Quaternion existingRotation = Quaternion.identity; Debug.Log($"Before SetLookRotation: {existingRotation}"); // Modifies in place existingRotation.SetLookRotation(direction); Debug.Log($"After SetLookRotation: {existingRotation}");

// Both produce the same result, but use different approaches: Debug.Log($"Results are equal: {newRotation.Equals(existingRotation)}");

// Usage patterns: // LookRotation: direct assignment transform.rotation = Quaternion.LookRotation(direction);

// SetLookRotation: modify then assign Quaternion rotation = transform.rotation; rotation.SetLookRotation(direction); transform.rotation = rotation; } }