Ask an AI tool for a character that turns to face the direction it walks, or a camera that swings smoothly behind the player, and the code usually looks like this:

1transform.rotation = Quaternion.Slerp(transform.rotation, target, 0.1f);

Then you click the object in the editor and the inspector offers three numbers in degrees — rotation X, Y, Z — and typing 90 into Y visibly turns it. The engine clearly understands three numbers. So why does the code hand it four?

The three numbers are what the engine shows you. The four are what it keeps. Why it keeps them tells you when to write slerp instead of lerp.

Three dials, and the pose they can't reach

Start with the version that feels obvious. Euler angles describe a 3D orientation as three ordered turns: pitch about X, yaw about Y, roll about Z. One angle was enough to spin a 2D sprite, so three angles for three ways to tilt sounds right.

The trap is that the turns happen one after another, and each one carries the previous ones with it. Turn an object 90° about Y and its X axis is no longer the world's X axis, so "rotate 30° about X" now means something different than it did a moment ago. Order therefore matters: (30°, 60°, 0°) is not the pose (60°, 30°, 0°) describes.

The worse consequence: at one particular middle angle, two of the three axes line up and two dials start doing the same job. The name for this is gimbal lock 2.

The game version: a first-person camera pitches up until it looks straight up. Its viewing axis is now vertical — the same line the yaw dial turns around. So "turn left" and "roll your head" have become the same movement. You command a yaw change and the picture doesn't turn, it spins around the middle of the screen. The camera can still pitch and still roll, but one of the three directions of motion is now unreachable through any combination of the three numbers.

That is not an engine bug and not a mistake in the generated code. It is what describing orientation with three ordered numbers costs, and no clever choice of axis order removes it — every order has its own bad angle somewhere 2.

Three nested gimbal rings around a small aircraft: when two rings end up with parallel axes, one direction of motion is no longer available.

The second thing three angles get wrong

Even far from gimbal lock, the three numbers lie about rotation in a quieter way: they don't blend honestly.

A turret should swing from 170° to −10°, a 20° turn the short way round. The numbers say 170 and −10, so a lerp between them travels 180° across the dial and lands on the far side of the circle. The pose at the end is right; the motion is a half turn to get 20° away.

So the three-number version fails twice over: a pose the dials can't reach, and a path between poses that spins the wrong way. Both come from the same source — the numbers describe a pose, and you can't safely do arithmetic on a description.

What the four numbers actually hold

Here is the fact that unlocks the whole thing: every rotation in 3D, however it was assembled, is a single turn by some angle around one fixed axis 1. You don't need three dials; you need to name a line in space and say how far to turn around it.

A quaternion packs exactly that into four numbers. With (x, y, z) the unit vector along the axis and θ the angle in radians:

q=(cos⁡θ2, sin⁡θ2x, sin⁡θ2y, sin⁡θ2z)=(w,x,y,z)q = \left(\cos\frac{\theta}{2},\ \sin\frac{\theta}{2}x,\ \sin\frac{\theta}{2}y,\ \sin\frac{\theta}{2}z\right) = (w, x, y, z)

Read it in two halves. x, y, z point along the axis of the turn, and their length is sin(θ/2) — short for a small turn, longest at half a turn. The fourth number w = cos(θ/2) is the balancing term that keeps the whole thing on the unit sphere, so that

w2+x2+y2+z2=1w^2 + x^2 + y^2 + z^2 = 1

Spin an object about Y in code and the four numbers appear directly:

1var q := Quaternion(Vector3.UP, deg_to_rad(90))
2print(q)  # (0, 0.707107, 0, 0.707107) — printed as x, y, z, w

The axis is (0, 1, 0), so x and z respond to nothing and all the turning shows up in y and w. A short table of turns about Y makes the pattern obvious:

Turn about YQuaternion (w, x, y, z)
0° (no rotation)(1, 0, 0, 0)
10°(0.996, 0, 0.087, 0)
90°(0.707, 0, 0.707, 0)
180°(0, 0, 1, 0)
350°(−0.996, 0, 0.087, 0)

Notice the last row: turning 350° gives almost the negative of "no rotation", and 360° gives exactly (−1, 0, 0, 0). That is the halved angle at work. The surface of a 4D unit sphere covers the space of 3D rotations twice over, so two quaternions that are negatives of each other mean the same orientation — q and −q rotate an object identically 1. Walking halfway around the sphere turns you all the way around your axis; walking all the way lands on −q; only two full walks bring you back to q.

Two consequences fall straight out of that: comparing quaternions component by component is meaningless, and interpolating between two of them means choosing between two arcs. (Component order is also not universal — formulas put w first, Godot prints x, y, z, w, Unity's constructor takes w last — so print one before trusting an order you copied.)

Why four numbers beat three

Four numbers, one equation between them, so three degrees of freedom — the same information the three angles carried. Nothing extra is stored. The gain is shape.

The set of all orientations is curved. Three independent dials make a flat grid over that curve, and every flat map of a curved surface has to break somewhere: gimbal lock is that break. Four numbers with a length constraint sit on the curve itself, so there is no seam to fall through. That's the trade: you give up human-readable degrees and accept the sign ambiguity where q and −q both work, and in return no pose is unreachable and no direction of motion disappears.

What slerp does that lerp can't

The previous article established that lerp(a, b, t) returns the point a fraction t of the way from a to b. For rotations, a and b are points on that 4D sphere, so blending the four numbers one at a time draws a straight line through the inside of the sphere — and points inside aren't orientations at all.

Engines patch this by renormalizing the result back onto the surface. That is precisely what Unity's Quaternion.Lerp does: "interpolates between a and b by t and normalizes the result afterwards" 3. It lands on the right pose at the ends and halfway, but the angle covered per unit of t is uneven — Unity's own docs warn that "the angular velocity will not be constant if the rotations are far apart" 3.

Run the numbers on a 180° turn a quarter of the way through. slerp gives exactly 45°, because it walks the arc and t is a fraction of the angle. Component-wise lerp plus normalization gives about 36.9°. Both are at 90° halfway, so the shape is: slightly slow at the start, slightly fast at the finish — an ease-in nobody asked for. Over a 90° turn the same error is under 1°, invisible; over a half turn it's 8°, and "swing round in 0.4 seconds" visibly lurches at the end.

Slerp is spherical linear interpolation: same three arguments, but t measures progress along the arc, so equal steps in t are equal steps in degrees 45. It also settles the sign question — if the two quaternions sit more than a quarter turn apart on the sphere, which means the rotations differ by more than 180°, it flips one and takes the other way round. Godot exposes that decision: slerp checks for the shorter path, slerpni ("no invert") skips the check and can spin the long way 5. Generated code that reaches for slerpni is how a turret ends up turning 340° to move 20°.

What this changes in the code you're directing

  • Keep rotations as quaternions; read Euler angles only for humans. Unity's docs say values read back from eulerAngles may differ from what you set, and recommend against incrementing them to animate 6. That's the real answer to "quaternion to euler": it's a display format, not a working one.
  • A timed turn is slerp(from, to, clamp(elapsed / duration, 0, 1)) — the same time-driven t as the earlier lerp pattern.
  • A chase toward a moving target is slerp(current, target, weight) every frame, and it inherits the same frame-rate problem as position = lerp(position, target, 0.1), so a weight built as 1 - exp(-k * delta) stays consistent across machines.
  • Check angles, not components. With q and −q being the same pose, == on four floats will eventually be false for a rotation that hasn't changed. Compare the angle between two rotations against a tolerance instead.
  • Never average or scale quaternions by hand. "Half of this rotation" isn't half of each number; that's what slerp to the other end is for.

The one-sentence version: three angles are a readable label for a pose, a quaternion is a set of coordinates you can actually do arithmetic on, and slerp is the arithmetic that respects the fact that rotations live on a curve.