Implementation guides
Use formulas safely in real games
A formula is only half the story. These guides cover the practical details that make math reliable in real-time game systems: units, coordinate systems, timestep, floating point, and performance.
1. Be explicit about units and coordinates
Many bugs come from mixing units (pixels vs meters), angle units (degrees vs radians), or coordinate conventions (y-up vs y-down). Decide these at the system boundary and convert deliberately.
2. Use delta time correctly
Frame-rate-independent movement scales by elapsed time. If your game runs at 30 FPS or 144 FPS, the same velocity should produce the same world-space movement per second.
3. Prefer squared distance for comparisons
When you only need to compare distances, compare squared values. This avoids unnecessary square roots in hot paths like collision checks, AI sensing, and proximity triggers.
4. Handle floating-point edge cases
Floating-point math has precision limits. Values that should be equal may differ by tiny amounts, and operations like normalization can fail on zero vectors.
5. Choose the right abstraction level
The code examples on this site are intentionally straightforward. In production, wrap them in tested math types, use engine/library primitives where appropriate, and add validation around inputs from gameplay scripts or network data.