A unit quaternion used for representing 3D rotations.
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: In a boolean context, a quaternion will evaluate to false if it's equal to IDENTITY. Otherwise, a quaternion will always evaluate to true.
W component of the quaternion. This is the "real" part.
Note: Quaternion components should usually not be manipulated directly.
X component of the quaternion. This is the value along the "imaginary" i axis.
Note: Quaternion components should usually not be manipulated directly.
Y component of the quaternion. This is the value along the "imaginary" j axis.
Note: Quaternion components should usually not be manipulated directly.
Z component of the quaternion. This is the value along the "imaginary" k axis.
Note: Quaternion components should usually not be manipulated directly.
Returns the angle between this quaternion and to. This is the magnitude of the angle you would need to rotate by to get from one to the other.
Note: The magnitude of the floating-point error for this method is abnormally high, so methods such as is_zero_approx will not work reliably.
Returns the dot product between this quaternion and with.
This is equivalent to (quat.x * with.x) + (quat.y * with.y) + (quat.z * with.z) + (quat.w * with.w).
Returns the exponential of this quaternion. The rotation axis of the result is the normalized rotation axis of this quaternion, the angle of the result is the length of the vector part of this quaternion.
Constructs a new Quaternion from the given Vector3 of Euler angles, in radians. In Godot, Euler angles always use intrinsic order. This method always uses the intrinsic YXZ convention (EULER_ORDER_YXZ).
Returns the angle of the rotation represented by this quaternion.
Note: The quaternion must be normalized.
Returns this quaternion's rotation as a Vector3 of Euler angles, in radians.
The order of each consecutive rotation can be changed with order (see EulerOrder constants). In Godot, Euler angles always use intrinsic order. By default, the intrinsic YXZ convention is used (EULER_ORDER_YXZ): since we are decomposing, local Z (roll) is calculated first, then local X (pitch), and lastly local Y (yaw). When using the opposite method from_euler() to compose a rotation, this order is reversed.
Returns the inverse version of this quaternion, inverting the sign of every component except w.
Returns true if this quaternion and to are approximately equal, by calling is_equal_approx() on each component.
Returns true if this quaternion is finite, by calling is_finite() on each component.
Returns this quaternion's length, squared.
Note: This method is faster than length(), so prefer it if you only need to compare quaternion lengths.
Returns a copy of this quaternion, normalized so that its length is 1.0. See also is_normalized().
Performs a spherical-linear interpolation with the to quaternion, given a weight and returns the result. Both this quaternion and to must be normalized.
Performs a spherical-linear interpolation with the to quaternion, given a weight and returns the result. Unlike slerp(), this method does not check if the rotation path is smaller than 90 degrees. Both this quaternion and to must be normalized.
Performs a spherical cubic interpolation between quaternions pre_a, this vector, b, and post_b, by the given amount weight.
Performs a spherical cubic interpolation between quaternions pre_a, this vector, b, and post_b, by the given amount weight.
It can perform smoother interpolation than spherical_cubic_interpolate() by the time values.
The identity quaternion, representing no rotation. This has the same rotation as Basis.IDENTITY.
If a Vector3 is rotated (multiplied) by this quaternion, it does not change.
Note: In GDScript, this constant is equivalent to creating a [constructor Quaternion] without any arguments. It can be used to make your code clearer, and for consistency with C#.