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:
- Evaluate Math Expression — Compute a math expression and store the result in a variable.
- If Math Expression — Branch based on a math condition.
- Loop While Math Expression — Repeat a block while a math condition is true.
- Math Functions — Access built-in math functions (sine, cosine, atan2, square root, etc.).
- Seed Random Number Generator — Set the random seed for reproducible results.
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
- Math Event Glossary — Full reference for all math events
- Engine Fields — Physics values that use the math module's unit conversion
- Collisions & Physics — The physics system that uses these math operations

