Quaternion Manual     Reference     Scripting  
Scripting > Runtime Classes > Quaternion
Quaternion Struct

Quaternions are used to represent rotations.

They are compact, don't suffer from gimbal lock and can easily be interpolated. Unity internally uses Quaternions to represent all rotations.

However, they are based on complex numbers and are not easy to understand intuitively. Thus you almost never access or modify individual Quaternion components (x,y,z,w); most often you would just take existing rotations (e.g. from the Transform) and use them to construct new rotations (e.g. to smoothly interpolate between two rotations). The Quaternion functions that you use 99% of the time (The other functions are only for exoctic uses) Quaternion.LookRotation, Quaternion.Angle, Quaternion.Euler, Quaternion.Slerp, Quaternion.FromToRotation, Quaternion.identity

You can use Quaternion.operator * to rotate one rotation by another, or to rotate a vector by a rotation.

Variables
x

X component of the Quaternion. Don't modify this directly unless you know quaternions inside out.

y

Y component of the Quaternion. Don't modify this directly unless you know quaternions inside out.

z

Z component of the Quaternion. Don't modify this directly unless you know quaternions inside out.

w

W component of the Quaternion. Don't modify this directly unless you know quaternions inside out.

this [int index]

Access the x, y, z, w components using [0], [1], [2], [3] respectively.

eulerAngles

Returns the euler angle representation of the rotation.

Constructors
Quaternion

Constructs new Quaternion with given x,y,z,w components.

Functions
Set

Set x, y, z and w components of an existing Quaternion.

ToAngleAxis

Converts a rotation to angle-axis representation.

SetFromToRotation

Creates a rotation which rotates from fromDirection to toDirection.

SetLookRotation

Creates a rotation that looks along forward with the the head upwards along upwards

ToString

Returns a nicely formatted string of the Quaternion

Class Variables
identity

The identity rotation (Read Only). This quaternion corresponds to "no rotation": the object

Class Functions
operator *

Combines rotations lhs and rhs.

operator ==

Are two quaternions equal to each other?

operator !=

Are two quaternions different from each other?

Dot

The dot product between two rotations.

AngleAxis

Creates a rotation which rotates angle degrees around axis.

FromToRotation

Creates a rotation which rotates from fromDirection to toDirection.

LookRotation

Creates a rotation that looks along forward with the the head upwards along upwards

Slerp

Spherically interpolates between from and to by t.

Lerp

Interpolates between from and to by t and normalizes the result afterwards.

RotateTowards

Rotates a rotation from towards to.

Inverse

Returns the Inverse of rotation.

Angle

Returns the angle in degrees between two rotations a and b.

Euler

Returns a rotation that rotates z degrees around the z axis, x degrees around the x axis, and y degrees around the y axis (in that order).