Billboarding
flat cards that always turn to face the camera
A billboard is a flat quad rotated every frame to face the camera, so a 2D image reads as 3D. Use full facing for sprites, Y-axis only for trees.
55 visual cheat sheets · AI-ready
Game development and physics concepts, each with an interactive Three.js visual, formulas, code and a prompt you can paste into your AI assistant. Every page is also available as Markdown for LLMs.
How a 3D scene becomes pixels: rays, normals, culling, shaders and the standard ways to draw less.
flat cards that always turn to face the camera
A billboard is a flat quad rotated every frame to face the camera, so a 2D image reads as 3D. Use full facing for sprites, Y-axis only for trees.
a tiny program that runs once for every pixel
A fragment shader computes the colour of each pixel a triangle covers. Feed it UVs, normals and a time uniform and it paints anything.
don't draw what the camera can't see
Frustum culling skips objects whose bounding volume lies fully outside the camera's six view planes, before any draw call is made.
spend triangles only where the player can see them
LOD swaps a mesh for cheaper versions as it shrinks on screen, so far objects cost a fraction of near ones. Hysteresis stops the swaps flickering.
shoot an invisible line and ask what it touches first
A ray is an origin plus a direction. Raycasting returns the nearest surface it crosses, with hit point, distance and surface normal.
the unit arrow that says which way a surface faces
A normal is a unit vector perpendicular to a surface. Lighting, slope checks, bounces and decals all start from it, so it must be right.
two surfaces, one depth value, endless flicker
Z-fighting is the shimmering stripes you get when two surfaces are closer than the depth buffer can resolve. Fix the geometry, the near plane or the bias.
The math under game code: rotations, interpolation and deterministic randomness.
four numbers that rotate without gimbal lock
A unit quaternion stores a 3D rotation as an axis and half-angle. It composes cheaply, never gimbal-locks and slerps along the shortest arc.
bend linear progress into motion with weight
An easing function remaps progress t from 0..1 so motion accelerates, decelerates, overshoots or bounces instead of moving at a robotic constant speed.
same seed in, same world out, every time
A seeded PRNG plus gradient noise and fBm turns one integer into an endless, smooth, repeatable world: same seed, same terrain on every machine.
Timing and motion rules that make jumps, hits and cameras respond the way players expect.
let the player jump a few frames after leaving the ledge
Coyote time keeps a jump available for ~0.1 s after the character walks off an edge, so presses that feel on time are not eaten by the game.
scale every change by how long the last frame took
Delta time is the seconds since the last frame. Multiply speeds and rates by it so a game plays the same at 30, 60 or 144 fps.
freeze both fighters for a few frames when a blow lands
Hit stop pauses the attacker and target for a few frames on impact. The brief freeze sells weight and gives the eye time to read the hit.
remember a press for a moment and fire it when it becomes legal
Input buffering stores a press for ~0.1 s and performs it as soon as the action becomes possible, so slightly early inputs still count.
after a hit, ignore damage for a short, clearly signalled window
Invincibility frames (i-frames) make a character ignore damage for a short window after a hit or during a dodge, with blinking to show it.
ramp velocity toward the input instead of snapping to it
Ramp velocity toward input × max speed with an acceleration, and back to zero with a separate deceleration, to give movement weight.
deform along the motion, keep the volume constant
Stretch an object along its velocity and squash it on impact, scaling the other axes so volume stays constant. Motion reads as fast and elastic.
let the player move inside a box before the camera follows
A camera deadzone is a box around the screen centre where the target moves freely. The camera only follows when the target pushes past its edge.
add trauma on impact, shake by trauma squared, let it decay
Trauma-based screen shake: hits add trauma (0–1) that decays over time, and the camera is offset by trauma² × smooth noise for impact.
Code patterns most games need for objects, effects, simulation and collision.
create everything up front, then recycle instead of allocate
Pre-allocate bullets, effects and enemies once, then hand out and return them. No allocation or GC spikes mid-fight, and a hard cap on live objects.
thousands of short-lived points, one draw call
An emitter spawns particles at a rate, each lives for a set time under simple forces, and all of them render in a single instanced draw call.
physics ticks at a steady rate, rendering just blends between ticks
Run physics in constant dt slices from an accumulator, clamp long frames, and interpolate between the last two states for smooth, repeatable motion.
attacks carry hitboxes, bodies carry hurtboxes, and they only meet on active frames
Attacks own hitboxes that exist only during active frames; characters own hurtboxes. An overlap is a hit, registered once per swing per target.
fast objects skip over thin walls between two ticks
A fast object can be on one side of a thin wall at one tick and past it at the next. Swept tests (CCD) check the whole path between positions.
Navigation, steering and decision-making for game characters.
expand the node that looks cheapest so far plus estimated cost to go
A* searches a graph by always expanding the node with the lowest cost so far plus estimated cost to go. With an admissible heuristic, the path is optimal.
steer toward a desired velocity, a little each frame
Seek, arrive and separation each compute a desired velocity; steering is desired minus current velocity, capped and summed. Simple rules, lifelike motion.
one state at a time, explicit events move between them
An FSM keeps an AI or character in exactly one state, such as Idle, Patrol, Chase or Attack. A table of events decides every legal transition.
Where the 16.67 ms of a frame go, and the standard ways to spend less of them.
every system shares one slice of time per frame
At 60 Hz a frame has 16.67 ms for input, gameplay, physics, AI and rendering combined. Measure each system and keep the total under budget with headroom.
let a different group think each frame
Split expensive per-entity work into buckets and run one bucket per frame. Cost per frame drops by the bucket count; each entity reacts a little later.
draw a thousand things in one request
Each mesh costs the CPU a draw call plus state changes. Instancing and batching turn thousands of identical objects into one call; track renderer.info.
every layer on a pixel is paid for again
Overdraw is shading the same pixel more than once. Stacked transparent particles and big quads multiply fill cost; trim sprites and limit layers.
many images, one texture, one material
Pack many sprites into one texture and address each by its UV rectangle, so objects share a material and batch into few draw calls. Pad to stop bleeding.
keep only the world around the player in memory
Split a big world into chunks, load those within a radius of the player and unload them past a larger radius, so the boundary never thrashes.
only compare things that are near each other
Bin objects into a uniform grid so collision and proximity queries test only same-cell and neighbour-cell pairs instead of all n(n−1)/2 pairs.
Interactive physics from forces and fields to quanta and curved spacetime, with the equations behind each model.
force times lever arm decides which way it turns
A lever balances when m₁r₁ = m₂r₂. Torque is force times lever arm, and net torque over moment of inertia gives angular acceleration.
the water pushes up with the weight of what you displace
Archimedes: a body is pushed up by the weight of fluid it displaces, so it floats with ρ_object/ρ_fluid of its volume under. Boats and crates in games.
a sine-shaped pull back to the bottom, minus friction
A swinging weight pulled by sin θ: its period is only 2π√(L/g) for small swings, and damping decays the arc. Grapples, lamps and ropes in games.
ellipses, equal areas, and T² ∝ a³
Orbits are ellipses with the star at one focus, sweep equal areas in equal times, and have T² ∝ a³. Place planets on rails exactly with Kepler's equation.
small launch errors become a spread of landing spots
Repeat a launch with a little speed error and the landings form a distribution. Mean, spread and why R ∝ v² shifts the average: the maths of weapon spread.
constant sideways speed, steadily changing vertical speed
Launch angle, speed and gravity fully determine a ballistic arc: x moves at constant speed while y accelerates downward.
everything orbits the shared centre of mass
Two gravitating bodies circle their shared barycentre: radii split by mass, period set by total mass. Plus a stable n-body integrator for games.
air molecules shuffle back and forth, the pattern travels
Sound is a longitudinal pressure wave: frequency sets pitch and wavelength, amplitude sets loudness. The physics behind 3D audio, delay and Doppler.
pull back in proportion, bleed energy, push in rhythm
Hooke's law, damping and a periodic push: the forced oscillator behind springy cameras, wobbly UI and suspension, and why driving at ω₀ explodes.
B bends, E pushes, together they drift
The Lorentz force curls a charge around magnetic field lines and crossed E and B make it drift sideways. Integrate it with Boris, not Euler.
add every charge's push, then follow the arrows
Coulomb fields add as vectors; tracing streamlines along the net field draws lines that leave positive charges, end on negative ones and never cross.
leapfrog E and B on a staggered grid
Light is E and B regenerating each other. A 1D Yee grid (FDTD) leapfrogs them in time, slows them in glass and blows up past the Courant limit.
high energy is possible, just exponentially rare
At temperature T a state of energy E is weighted by e^(−E/kT). Metropolis sampling reproduces the distribution with a simple accept/reject rule.
each cell drifts toward the average of its neighbours
Heat flows down temperature gradients at a rate set by the Laplacian. The explicit grid update is four lines of code, and is stable only if αΔt/Δx² ≤ ¼.
pressure is just particles bouncing off walls
Temperature is average kinetic energy and pressure is momentum delivered to the walls. Bounce point particles in a box and PV = NkT falls out.
a cloud of probability that spreads, scatters and interferes
A Gaussian wave packet in 2D drifts, spreads and splits at a potential bump; brightness shows |ψ|² and colour shows the quantum phase.
walls force whole half-waves, so energy comes in steps
A particle trapped between hard walls can only hold standing waves, so its energy is quantized as n² and superpositions slosh at beat frequencies.
a wave leaks through a wall it can't climb
A quantum packet hitting a barrier higher than its energy still partly gets through: transmission falls off exponentially with barrier width.
orbiting masses shake spacetime at twice their orbit rate
A compact binary radiates gravitational waves at twice its orbital frequency; chirp mass and distance set a strain of around 10⁻²¹ or smaller.
more mass, deeper well, tighter orbits
Mass curves spacetime: picture a gravity well whose depth follows −GM/r, with the Schwarzschild radius 2GM/c² marking where light can no longer escape.
relativity keeps the ellipse from quite closing
General relativity adds a small 1/r⁴ pull that makes an orbit's closest point creep forward each lap: about 43 arcseconds per century for Mercury.