Game Development Math Recipes

One of the most daunting aspects of game development for many people is the mathematics involved.  The following are a collection of recipes that go into detail on how to perform a number of common math related tasks.  Each example ships with at least one working demonstration application (written in JavaScript using EaselJS), with complete source code.  Don’t worry if your language of choice is C++, C# or Java, the JavaScript code is easily ported to any C derived language. In every case, the code is written to favor readability over performance.


Velocity and angular velocity

Got something you want to make move? This is the recipe for you! Actually, it’s two recipes in one. The first covers working with velocity, that is, applying movement in a given direction along an axis at a given speed. It also covers how to normalize the frame rate using the elapsed time per frame. The second covers applying velocity along a given angle.

Tutorial Link


Rotating one object relative to another

Rotating about the origin is easy, but sometimes you want to rotate relative to the location of another object. This recipe illustrates how to do exactly that, showing how to rotate a point around another point.

Tutorial Link


Rotating to face another object

Sometimes you want to rotate to look at another object. In this example, our sprite rotates relative to the position of the mouse cursor. This is done by calculating the angle between two different locations.

Tutorial Link


Collision detection using an axis aligned bounding box: Part 1

Bounding boxes are often used for performing collision detection. Axis aligned bounding boxes are very high performance way implementation. This recipe looks at the details of axis aligned bounding boxes and shows how to implement a collision detection method.

Tutorial Link


Collision detection using an axis aligned bounding box: Part 2

One of the major downsides to using an axis aligned bounding box is they cannot be rotated. Instead, you need to resize the bounding box to contain the dimensions of your newly rotated sprite. This recipe illustrates how to do exactly this.

Tutorial Link


Collision detection using a bounding circle

The bounding circle removes a great deal of the complexity you need to deal with when using bounding boxes, especially when it comes to rotation.  This tutorial demonstrates how to create a bounding circle and check for intersections against another bounding circle

Tutorial Link


Handling sprite based shooting

This recipe puts what you have learned in a couple of prior recipes together to accomplish a common task, firing guns.  Click in the app to fire a bullet, the further from the jet the faster the bullet travels.  When it leaves the screen it is removed.

Tutorial Link


Scroll to Top