Quaternion class represents a 3D rotation as four components — x, y, z, and w. Quaternions avoid the gimbal-lock problems of Euler angles and compose cleanly, making them the preferred way to describe rotations in RollingQuest scripts. You typically pair a Quaternion with a Vector3 to build a full transform: the Vector3 carries the position and the Quaternion carries the orientation. The most common constructors you’ll reach for are Quaternion.euler (when you think in degrees), Quaternion.angleAxis (when you want to spin around a specific axis), and Quaternion.lookRotation (when you need something to face a direction).
Constructors
Instance Properties
You can also index a
Quaternion by integer position (q[1] → x, q[2] → y, q[3] → z, q[4] → w) for read and write access.
Static Constants
Instance Methods
copy
Returns a new Quaternion with the same component values.
set
Mutates the quaternion in place by assigning all four components.
normalize
Normalises the quaternion in place. To get a normalised copy without mutating the original, read the normalized property.
setLookRotation
Mutates the quaternion so the local forward faces view, optionally constraining the local up.
setFromToRotation
Mutates the quaternion to the shortest rotation from fromDirection to toDirection.
Static Methods
slerp
Spherically interpolates between two rotations by the clamped factor t.
slerpUnclamped
Same as slerp but t is not clamped to [0, 1].
lerp
Linearly interpolates between two quaternions and normalises the result. Faster than slerp when the two rotations are close together.
lerpUnclamped
Unclamped variant of lerp.
dot
Returns the dot product of two quaternions, which is useful for checking how similar two rotations are.
angle
Returns the angle in degrees between two rotations.
rotateTowards
Rotates from toward to by at most maxDegreesDelta degrees per call.
Usage Examples
Rotating a projectile direction
When you fire a projectile you often want it to travel in the direction the character is facing, possibly with an upward arc. UseQuaternion.euler to build the offset, then multiply it by a Vector3 representing the base forward direction.
Smoothly turning to face the player
Reading and writing Euler angles
Vector3 and Quaternion are used together for transforms throughout RollingQuest. A Quaternion stores the orientation while a Vector3 stores the position. The * operator can apply a Quaternion rotation to a Vector3 direction.