36 · Animation · 3D

Quaternions

Rotations that do not lock up or take the long way round.

Storing rotation as three angles (Euler) fails in two ways: at some orientations two axes line up and you lose one (gimbal lock), and interpolating each angle separately takes strange paths. Quaternions store rotation as one axis and amount, and slerp turns along the shortest arc at steady speed.

Q Euler / quaternionSpace play the turnUse the buttons

Try this: Play the turn with Euler interpolation: the arrow swings wide. Switch to quaternion slerp (Q) and play it again.

Total rotation travelled 0°

Play the turn.

Prompt bit

Works for 2D or 3D in any engine (Unity, Unreal, Godot, web). Paste the short one for a quick fix, or the detailed one when you want it done properly.

Store and blend rotations as quaternions: slerp between orientations over time (for example a 0.3 s turn), flip one quaternion when their dot product is negative so it takes the short way, renormalize after many multiplications, and only convert to Euler angles for display.

44 words · one sentence to paste as is

Where it's used

Common mistakes

Lerping Euler angles so turns wobble or spin the long way, forgetting the negative dot check, accumulating rotation without renormalizing, wrong multiplication order, and building first-person cameras from one quaternion so the horizon rolls.

Writing this with an AI assistant? See our best AI coding assistants for game developers.

Missing a concept? Request one.

Related concepts

New concepts, in your inbox.

One short email when we add new concepts, plus our weekly roundup of AI tools for game devs. Unsubscribe any time.