Quaternion API in Core

The Quaternion API page will have basic information for creating and using quaternions in Core.


There are a few useful ways to create Quaternions.

--Using a Rotation to create a Quaternion
local q1 = Quaternion.New(Rotation.New(0, 90, 0))

--Use two positional vectors to create a Quaternion
local q2 = Quaternion.New(Vector3.UP, -Vector3.UP)

--Use a Euler axis vector and rotation angle to create a Quaternion
local q3 = Quaternion.New(Vector3.RIGHT, 45)Code language: PHP (php)


There is only one constant for quaternions.

--Create a Quaternion with the values (0, 0, 0, 1)
local q1 = Quaternion.IDENTITYCode language: JavaScript (javascript)


Quaternions have four properties for each component (x, y, z, w).

--Print the w component of a Quaternion
print(Quaternion.IDENTITY.w)Code language: CSS (css)


Quaternions have functions to return the three positional vectors and the rotation.

local q1 = Quaternion.New(0.2, 0.3, 0, 1)

--Create a forward vector from the Quaternion
local fv = q1:GetForwardVector()

--Create a rotation from the Quaternion
local r1 = q1:GetRotation()Code language: JavaScript (javascript)


Quaternion has a class function named Slerp that can return a certain transition progression between two quaternions. This can be useful to animation an object’s rotation.

local q1 = Quaternion.IDENTITY
local q2 = Quaternion.New(Vector3.UP, 120)

local progress = 0.5

--Create a Quaternion halfway between two others
local halfwayQuaternion = Quaternion.Slerp(q1, q2, progress)Code language: PHP (php)


Quaternions can handle math operations, similar to a Vector3. This can be useful for applying a direction to a position.

-- Multiplying two components will produce a quaternion that is the composite result.
local rotate90Degrees = Quaternion.New(Vector3.UP, 90)
local rotate180Degrees = rotate90Degrees * rotate90Degrees
local rotate360Degrees =  rotate180Degrees * rotate90Degrees * rotate90DegreesCode language: PHP (php)
Scroll to Top