How do video games know which way is forward for a spaceship?

A game stores the ship's angle and turns it into a forward direction with trigonometry: cosine of the angle is the sideways part and sine is the up part. Thrust adds speed along that direction to the speed the ship already had. In space nothing slows you down, so the ship drifts, sliding sideways even while it points somewhere else.

Facing 220°: forward = (cos 220°, sin 220°) = (-0.77, -0.64)blue: drift (72.1 px/s)orange: burn adds 60result: 79.8 px/stravel 280°, facing 220°drift: 60.1° left of nosethe arena wraps around:fly off one edge, come backon the other
Speed after the burn
79.8 px/s
Direction of travel
280°
Travel minus facing (drift)
60.1°

Challenge: Starting with a drift to the right, end up flying straight up (90°, within 2°).

0° points right; angles go counterclockwise, so 90° points straight up.
More settings
px/s
Speed added per second of thrust (px/s every second).
px/s
px/s

Play

Try "Thrust up while drifting right," then press "Run it: fly." Can you make the ship fly straight up?

Challenge: Starting with a drift to the right, end up flying straight up (90°, within 2°). The box under the picture turns green when you get it.

Stuck? Pick one of the examples from the “Try an example” menu, or press “New example.”

Understand

v⃗=v⃗0+a t (cos⁡θ, sin⁡θ)\vec v = \vec v_0 + a\,t\,(\cos\theta,\ \sin\theta)

A game stores the ship's angle θ\theta. To move "forward," it turns that angle into a direction using trigonometry: (cos⁡θ, sin⁡θ)(\cos\theta,\ \sin\theta), an arrow one unit long. Thrusting for tt seconds adds a ta\,t along that arrow to the velocity you already have:

v⃗=v⃗0+a t (cos⁡θ, sin⁡θ)\vec v = \vec v_0 + a\,t\,(\cos\theta,\ \sin\theta)

That's vector addition. The picture shows it tip to tail: blue is your drift, orange is what the burn adds, and the thick line is where you end up going. Press "Run it: fly" to watch, and fly off an edge to wrap around like classic Asteroids.

Use

Every input has a unit menu, so you can type values in the units you already have. Results follow your units.

Show the work

  1. Forward for a ship pointing at θ: cosine is the sideways part, sine the up part(\cos 220^\circ,\ \sin 220^\circ) = (-0.766,\ -0.643)
  2. Thrust adds speed in that direction, thrust × time120 \times 0.5 = 60\ \text{px/s}
  3. Add it to the drift you already had (vectors add tip to tail)\vec v = (60, -40) + 120 \times 0.5 \times (\cos 220^\circ, \sin 220^\circ) = (14,\ -78.6)
  4. Speed and direction of the result\sqrt{14^2 + -78.6^2} = 79.8,\quad \tan^{-1}\frac{-78.6}{14} \to 280^\circ

Export

Export PDF

Set the angle and how long you hold thrust. "More settings" changes the engine's power and your starting drift.

  • Many games add a little "space friction" so ships slowly stop. This one is the pure version.

For learning and estimation. Verify with applicable codes, standards, and a qualified professional before using in design, construction, or safety-critical work.

Cheat card

forward=(cos⁡θ, sin⁡θ)\text{forward} = (\cos\theta,\ \sin\theta)
v⃗=v⃗0+a t (cos⁡θ, sin⁡θ)\vec v = \vec v_0 + a\,t\,(\cos\theta,\ \sin\theta)
speed=vx2+vy2\text{speed} = \sqrt{v_x^2 + v_y^2}
SymbolMeaningUnit
θ\thetaship angle (0° = right)°
aathrust: speed added per secondpx/s²
tthow long you hold thrusts
  • At 0° forward is (1, 0), at 90° it's (0, 1), and at 45° it's about (0.71, 0.71).
  • To stop, point backward and thrust. You're adding a vector that cancels your drift.
  • Real games multiply by the frame time every frame, but over a burn it adds up to thrust × time.

Print this card

Where it’s used

  • Computer Science
    Every game with a turning character, from Asteroids to racing games, computes forward from cos and sin of its angle.
  • Physics
    Real spacecraft steer the same way: they point the engine and add velocity, because nothing slows them down.
  • Hobbies & Crafts
    Space-sim players learn to burn sideways to cancel their drift before docking.

Questions people ask

Why does my spaceship keep drifting?

In space there's no air or ground to slow you, so your velocity stays until you thrust the other way. Pointing a new direction doesn't change where you're going.

What do cos and sin have to do with direction?

For a ship pointing at angle θ, cos θ is how much of each step goes sideways and sin θ how much goes up. Together they make an arrow one unit long in that direction.

How do I fly straight in a new direction?

Thrust so the new push cancels your old drift and adds the new direction. The vector arrows show it. The orange burn has to close the gap between your drift and where you want to go.

Updated : First published.

See everything that’s new on Maps for Math