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.
Try this: Play the turn with Euler interpolation: the arrow swings wide. Switch to quaternion slerp (Q) and play it again.
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.
Use quaternions for 3D rotation (every engine: Unity Quaternion, Unreal FQuat, Godot Quaternion, three.js Quaternion). Store object orientation as a quaternion, not Euler angles. Turn toward a direction with LookRotation or from-to rotation. Interpolate with slerp (or nlerp for speed) and frame-rate independent factors: q = slerp(q, target, 1 - exp(-dt / tau)), or a fixed-duration turn like 0.3 s with easing. Before blending, if dot(a, b) < 0, negate b so the path is the short way. Compose rotations by multiplication (order matters) and renormalize occasionally. Use Euler angles only for editor input and UI, and for first-person cameras keep yaw and pitch as two separate floats and clamp pitch to avoid flipping. Never interpolate Euler angles component-wise.
Where it's used
- 3D characters: turning to face a direction
- Cameras: smooth orbit and look-at
- Flight and space games: free 6DOF rotation without gimbal lock
- Animation: bone rotations blended in skeletons
- VR: head and hand orientation
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.


