Quaternion

2025/12/27

Type
Learning Resource
Format
Glossary Article
Version
General
Subject Tags
Code
Assets
All else
Copyright 2016-2026, GDQuest
Created
2026/02/16
Updated
2025/12/27

Quaternion

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):

  1. The first three, (x, y, z), control the axis of rotation.
  2. w determines the angle of rotation around that axis.
These values are not angles!

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:

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.

Become an Indie Gamedev with GDQuest!

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.

Nathan

Founder and teacher at GDQuest
  • Starter Kit
  • Learn Gamedev from Zero
Check out GDSchool

You're welcome in our little community

Get help from peers and pros on GDQuest's Discord server!

20,000 membersJoin Server

Contribute to GDQuest's Free Library

There are multiple ways you can join our effort to create free and open source gamedev resources that are accessible to everyone!