A library of useful math classes & functions for game development, involving linear algebra, trigonometry, RNG, and more.
# choose based on your package manager
npm i @writegames.com/game-math
pnpm add @writegames.com/game-math
yarn add @writegames.com/game-math- Vec2, Vec3, Vec4, Mat2, Mat3, and Mat4 classes
- Dot products, cross products, vector-matrix multiplication, transformation matrices, and more
- Random class
- Uses
xorShift32as default random function float(n)- returns a random float between [0, n) (exclusive)chance(n, max)- returnstrueorfalsebased off ofninmaxchances (ex:chance(1, 5)would return true 20% of the time)int(n)- returns a random int between [0, n) (exclusive) (ex:int(3)would return0,1, or2)range(a, b)- returns a random float between [a, b) (exclusive)bool()- returnstrueorfalsesign()- returns-1or1angle()- returns a random angle in degrees [0, 360)choose(...items)- returns a random item from the items passed (ex:choose(1, 2, 3)would return1,2, or3)shuffle(arr)- shuffles an array using the Fisher–Yates shuffle algorithmvec2(scale)- returns a random Vec2 of the length ofscale(defaults to1)vec3(scale)- returns a random Vec3 of the length ofscale(defaults to1)
- Uses
- WIP
- WIP
While this is pre-1.0, GameMaker compatibility may be incomplete and/or broken.
© 2025 WriteGames.com. MIT License