Quaternion represents a 3D rotation as four components (x, y, z, w).
Bone orientations, hitbox transforms, and any rotation that needs to
compose or interpolate cleanly use this type instead of
QAngle.
Identity is
(0, 0, 0, 1). A unit quaternion has
x² + y² + z² + w² = 1. After repeated multiplication, call
normalize() to correct drift.Overview
Creating quaternions
Identity, explicit components, array, or object forms.
Arithmetic
Hamilton product, scalar scaling, conjugate, inverse.
Rotation
Rotate vectors, interpolate between orientations.
Conversion
To and from Euler angles and axis-angle form.
Components
All four are read/write properties:
Creating quaternions
Constructor
(0, 0, 0, 1).
- Identity
- Components
- Array / object
Quaternion.identity
(0, 0, 0, 1). Equivalent to
new Quaternion() but reads better as a named factory.
Quaternion.fromAxisAngle
degrees around axis. The axis does not need to
be pre-normalized.
Quaternion.fromEulerAngles
QAngle (pitch / yaw / roll in degrees)
into a quaternion.
Arithmetic
All arithmetic methods return a new Quaternion - the original is never modified. Exceptions are noted inline.add
sub
mul
a.mul(b) applies b first, then a.
Quaternion × number - scales each component by the scalar.
div
a * b⁻¹) or component-wise scalar division.
dot
1 means identical orientation,
-1 means opposite hemisphere (but same rotation - quaternions are
double-covers).
conjugate
(-x, -y, -z, w). For a unit quaternion this equals
inverse() and is faster.
inverse
conjugate / lengthSqr. Equals conjugate() when q is
already unit-length.
normalize
this for chaining.
normalized
length
√(x² + y² + z² + w²). Unit quaternions return 1.
lengthSqr
length() when comparing magnitudes.
Rotation
rotate
vec by this quaternion. Returns a new Vector.
Quaternion.slerp
a and b. Constant angular
velocity - use this for smooth camera or bone interpolation.
Quaternion.lerp
slerp and visually indistinguishable for small t - prefer it for
per-frame smoothing. Result is normalized for you.
Conversion
toEulerAngles
QAngle
(pitch / yaw / roll in degrees).
toAxisAngle
Utility
equals
false if other is not a
Quaternion.
clone
set
this.
setIdentity
(0, 0, 0, 1). Returns this for chaining.
toArray
[x, y, z, w] as a plain array.
toString
Common patterns
- Rotate a hitbox offset
- Smooth bone blending
- View angle as quaternion