Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

Quaternion

A unit quaternion used for representing 3D rotations.

Description

The Quaternion built-in Variant type is a 4D data structure that represents rotation in the form of a Hamilton convention quaternion. Compared to the Basis type which can store both rotation and scale, quaternions can only store rotation.

A Quaternion is composed by 4 floating-point components: w, x, y, and z. These components are very compact in memory, and because of this some operations are more efficient and less likely to cause floating-point errors. Methods such as get_angle, get_axis, and slerp are faster than their Basis counterparts.

For a great introduction to quaternions, see this video by 3Blue1Brown. You do not need to know the math behind quaternions, as Godot provides several helper methods that handle it for you. These include slerp and spherical_cubic_interpolate, as well as the * operator.

Note: Quaternions must be normalized before being used for rotation (see normalized).

Note: Similarly to Vector2 and Vector3, the components of a quaternion use 32-bit precision by default, unlike float which is always 64-bit. If double precision is needed, compile the engine with the option precision=double.

Note

There are notable differences when using this API with C#. See C# API differences to GDScript for more information.

Tutorials

Properties

float

w

1.0

float

x

0.0

float

y

0.0

float

z

0.0

Constructors

Quaternion

Quaternion()

Quaternion

Quaternion(from: Quaternion)

Quaternion

Quaternion(arc_from: Vector3, arc_to: Vector3)

Quaternion

Quaternion(axis: Vector3, angle: float)

Quaternion

Quaternion(from: Basis)

Quaternion

Quaternion(x: float, y: float, z: float, w: float)

Methods

float

angle_to(to: Quaternion) const

float

dot(with: Quaternion) const

Quaternion

exp() const

Quaternion

from_euler(euler: Vector3) static

float

get_angle() const

Vector3

get_axis() const

Vector3

get_euler(order: int = 2) const

Quaternion

inverse() const

bool

is_equal_approx(to: Quaternion) const

bool

is_finite() const

bool

is_normalized() const

float

length() const

float