ENGINE MATH
Direction Vector Calculator
Convert angles to 2D direction vectors and back using Unity/Godot or math conventions.
VECTOR MATH
Convert angles and vectors
Direction vector guide
Every game developer hits the same wall: an angle in degrees, but the engine wants a direction vector — or a vector from the physics engine and you need the angle for a UI compass. The catch is the convention: Unity and Godot measure 0° pointing up, while math textbooks measure it pointing right. This calculator handles both.
Two conventions, one atan2
In pure math, 0° points along +X and angles increase counterclockwise: vector = (cos θ, sin θ). In Unity and Godot, 0° points along +Y (up) and angles increase clockwise: vector = (sin θ, cos θ). Same numbers, swapped axes — the source of countless "my projectile flies sideways" bugs.
The inverse uses atan2, which has the same swap: Unity angle = atan2(x, y), math angle = atan2(y, x). Using the wrong atan2 order returns a perpendicular angle — a 90° error that is infuriating to debug because it is always exactly wrong.
Why atan2 and not atan
atan(y/x) loses the quadrant information — it cannot tell 135° from −45°. atan2(y, x) takes both components and returns the full 360° range. Always use atan2 for angle-from-vector work; atan is only correct when you already know the quadrant.
Tip: When porting code between engines, write a tiny wrapper pair (angleToVector / vectorToAngle) at the boundary instead of scattering sin/cos/atan2 through the codebase. One place to fix when conventions change.
Frequently asked questions
How do I get a direction vector from an angle in Unity?
Vector2 direction = new Vector2(Mathf.Sin(angleRad), Mathf.Cos(angleRad)). In Godot: Vector2.FromAngle(angleRad). This calculator gives you the numbers for any angle.
How do I get the angle of a vector?
Unity: Mathf.Atan2(v.x, v.y) * Mathf.Rad2Deg. Math convention: Math.atan2(v.y, v.x) * 180/Math.PI. The argument order is the entire difference.
Why is my angle 90° off?
You mixed conventions — likely used the math formula (cos, sin) in a Unity-style 0°-up system, or atan2 with swapped arguments. Pick one convention per function and stick to it.
Privacy note: vector calculations happen in your browser. Nothing is uploaded.