A library of useful math classes & functions for game development, involving linear algebra, angles, and more.
npm install @writegames.com/game-mathA library of useful math classes & functions for game development, involving linear algebra, trigonometry, RNG, and more.

``sh`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 xorShift32 as default random functionfloat(n)
- - returns a random float between 0, n) (exclusive)chance(n, max)
- - returns true or false based off of n in max chances (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 return 0, 1, or 2)range(a, b)
- - returns a random float between [a, b) (exclusive)bool()
- - returns true or falsesign()
- - returns -1 or 1angle()
- - returns a random angle in degrees [0, 360)choose(...items)
- - returns a random item from the items passed (ex: choose(1, 2, 3) would return 1, 2, or 3)shuffle(arr)
- - shuffles an array using the Fisher–Yates shuffle algorithmvec2(scale)
- - returns a random Vec2 of the length of scale (defaults to 1)vec3(scale)
- - returns a random Vec3 of the length of scale (defaults to 1`)
- WIP
- WIP
While this is pre-1.0, [GameMaker compatibility may be incomplete and/or broken.
© 2025 WriteGames.com. MIT License