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.
- 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°).
More settings
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
A game stores the ship's angle . To move "forward," it turns that angle into a direction using trigonometry: , an arrow one unit long. Thrusting for seconds adds along that arrow to the velocity you already have:
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
- 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) - Thrust adds speed in that direction, thrust × time
120 \times 0.5 = 60\ \text{px/s} - 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) - 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
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
| Symbol | Meaning | Unit |
|---|---|---|
| ship angle (0° = right) | ° | |
| thrust: speed added per second | px/s² | |
| how long you hold thrust | s |
- 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.
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.
Related exhibits
- Start here
Bounce: how many bounces until it stops?
Every bounce keeps a share of the speed, so each one is a fixed fraction of the last. The bounces never quite end, yet the ball still stops in a few seconds.
- Go further
Frame rate: why some games go slow-mo when they lag
Move 5 pixels every frame and your speed depends on the frame rate. Multiply by the time per frame instead, and every computer runs the same speed.
- Also try
Crossing a river: where you aim vs. where you end up
Your speed and the current add as arrows. Aim straight across and you drift; aim upstream and you can land right on target.
- Also try
Crosswind landing: splitting the wind into two parts
Pilots break the wind into “along the runway” and “across it.” That’s vector math at 60 knots.
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.