Upset Baby Games

Upset Baby Games


UBG Math

Getting Started

While GameMaker is a fantastic game creation tool, it is missing a large amount of basic mathematical functions. Most of this being the lack of proper vectors.

The UBG Math extension simply tries to fill this gap by adding numerous vector functions as well as some severely needed matrix functions. The supported vector types are vector2, vector3, vector4 and quaternions.

With this extension you can perform you basic vector math such as cross products, dot products, and normalization. Also included are game-related functions such as calculating a "bounce" vector, projecting a vector onto a plane for slide collisions, rotating vectors around eachother or by angles, lerp, slerp, nlerp, and more.

Vector data structures are handled just like matrices. They are simply arrays with a set number of elements inside of them. You can create a vector simply by creating an array. You can also convert between vector types and check if a value is a vector with the system scripts.

As an example, let's say we want to make a transformation matrix from a vector / quaternion pair, transform a vector by it, then output the result. It could look something like this:

center_v = [10, 10, 0]; // Create vector to rotate around
rotation_q = quat_from_axis([0, 0, 1], pi / 180 * 90); // Create rotation quaternion based on axis / angle pair
matrix = matrix_from_quatvec(rotation_q, center_v); // Generate our transform matrix

result = matrix_multiply_vector(matrix, some_4d_vector); // Transform our 4D vector
show_message(vector_string(vector3(result))); // Display as a 3D vector

If you have any questions or issues that can't be found in this manual please feel free to contact us!
If you like this extension take a look at some of our other offerings!

Folder contents: