Skip to main content

Math

The math module provides mathematical functions and unit conversions used by the engine and available to your scripts.

Unit Conversion

The engine uses an internal fixed-point number format (FF32) for physics calculations. The math module automatically converts values you specify in pixels per frame or pixels per frame squared into this internal format, so you don't need to worry about the conversion yourself.

This means you can set velocity and acceleration values in intuitive units and the engine handles the rest.

Math Functions

The module provides implementations of common mathematical functions:

  • Sine and Cosine — For circular motion, wave patterns, and angle-based calculations.
  • Atan2 — For calculating the angle between two points, useful for aiming or rotating toward a target.
  • Integer Square Root — For distance calculations and other operations that need a square root.

These operations are based on lookup tables and favor speed over accuracy, which is appropriate for a game running on the Mega Drive hardware.

Scripting Events

The math module's scripting events let you evaluate expressions and use math in control flow:

Tips

  • Use sine and cosine to create circular or wave-based movement patterns for enemies or projectiles.
  • Atan2 is useful for making an actor face toward the player or a target position.
  • If you need reproducible randomness (e.g., for replays or seeded levels), use the seed event at the start of the scene.

See Also