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.
They are based on complex numbers and are not easy to understand intuitively.
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 are:
Quaternion.LookRotation, Quaternion.Angle, Quaternion.Euler, Quaternion.Slerp, Quaternion.FromToRotation, and Quaternion.identity. (The other functions are only for exotic uses.)
You can use the Quaternion.operator * to rotate one rotation by another, or to rotate a vector by a rotation.
Note that Unity expects Quaternions to be normalized.
identity | The identity rotation (Read Only). |
eulerAngles | Returns or sets the euler angle representation of the rotation. |
normalized | Returns this quaternion with a magnitude of 1 (Read Only). |
this[int] | Access the x, y, z, w components using [0], [1], [2], [3] respectively. |
w | W component of the Quaternion. Do not directly modify quaternions. |
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. |
Quaternion | Constructs new Quaternion with given x,y,z,w components. |
Set | Set x, y, z and w components of an existing Quaternion. |
SetFromToRotation | Creates a rotation which rotates from fromDirection to toDirection. |
SetLookRotation | Creates a rotation with the specified forward and upwards directions. |
ToAngleAxis | Converts a rotation to angle-axis representation (angles in degrees). |
ToString | Returns a formatted string for this quaternion. |
Angle | Returns the angle in degrees between two rotations a and b. |
AngleAxis | Creates a rotation which rotates angle degrees around axis. |
Dot | The dot product between two rotations. |
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; applied in that order. |
FromToRotation | Creates a rotation which rotates from fromDirection to toDirection. |
Inverse | Returns the Inverse of rotation. |
Lerp | Interpolates between a and b by t and normalizes the result afterwards. The parameter t is clamped to the range [0, 1]. |
LerpUnclamped | Interpolates between a and b by t and normalizes the result afterwards. The parameter t is not clamped. |
LookRotation | Creates a rotation with the specified forward and upwards directions. |
Normalize | Converts this quaternion to one with the same orientation but with a magnitude of 1. |
RotateTowards | Rotates a rotation from towards to. |
Slerp | Spherically interpolates between quaternions a and b by ratio t. The parameter t is clamped to the range [0, 1]. |
SlerpUnclamped | Spherically interpolates between a and b by t. The parameter t is not clamped. |
operator * | Combines rotations lhs and rhs. |
operator == | Are two quaternions equal to each other? |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.