Quaternion
2025/12/27
- Type
- Learning Resource
- Format
- Glossary Article
- Version
- General
- Subject Tags
- Created
- Updated
- 2026/02/16
- 2025/12/27
A quaternion is a mathematical representation used to describe 3D rotations in a way that avoids the "gimbal lock" problem associated with Euler angles.
In Godot, quaternions are implemented through the Quaternion class and provide a compact, efficient way to represent orientations in 3D space.
Quaternions store rotation as four values, (x, y, z, w):
(x, y, z), control the axis of rotation.w determines the angle of rotation around that axis.The values of a quaternion are not angles like the x, y, and z values of Euler angles. They are not exactly like an arbitrary vector either.
The way the values work is a bit more complex. That said, in practice, you do not need to understand the values to use them effectively in Godot. You'll work with functions that convert between quaternions and other representations, like Euler angles or transform matrices.
Here's a breakdown of how quaternions work:
n = (nx, ny, nz), where nx, ny, and nz are the components of the vector.n as theta. It's the desired angle of rotation in radians.Here's how we can convert this information into a quaternion:
w = cos(theta / 2)
x = nx * sin(theta / 2)
y = ny * sin(theta / 2)
z = nz * sin(theta / 2)While less intuitive than Euler angles (pitch, yaw, roll), quaternions give you smooth and lock-free interpolation between rotations (we call that spherical-lerp or "slerp" for short). They don't have the Gimbal lock issue that Euler angles do, which means you can smoothly rotate between any two orientations without running into problems where the rotation axes align and prevent rotation.
Don't stop here. Step-by-step tutorials are fun but they only take you so far.
Try one of our proven study programs to become an independent Gamedev truly capable of realizing the games you’ve always wanted to make.
Get help from peers and pros on GDQuest's Discord server!
20,000 membersJoin ServerThere are multiple ways you can join our effort to create free and open source gamedev resources that are accessible to everyone!
Sponsor this library by learning gamedev with us onGDSchool
Learn MoreImprove and build on assets or suggest edits onGithub
Contributeshare this page and talk about GDQUest onRedditYoutubeTwitter…