Project Mirabelle - Blog

Working collisions! (technical article)

Written by ♫Dex, published 2024-03-26

Note: This article was written on 2025-01-04, as a summary of the events happening on Discord back during this development log

Collisions is something I've been working on and off for a few months at this point, ever since the first prototype outdoor levels. And, on March 26th, I got it working!

My first prototype tried to use the navigation mesh as collision 'source of truth', but I could not get the math to work properly. Instead, I decided to stop relying on navmeshes and to implement collisions simply through simple bounding boxes.

Collision boxes are a simple (x y z) (w h l) (yAngle) structure, only allowing rotations around the Y axis. This makes formula for the collision quite simple, as the algorithm ends up being a rotation, translation and an AABB check:

// One-dimensional Y collisio
if (c.y - c.h < p.y) return false; 
if (c.y + c.h > p.y) return false;
// Project X and Z into the box's coordinate
const x = c.x + xFromOffsetted(p.x, p.z, c.YAngle);
const z = c.z + zFromOffsetted(p.x, p.z, c.YAngle);
// Do an AABB check against the bo
if (x < -c.l || x > c.l) return false;
if (z < -c.w || z > c.w) return false;
return true;

This made it very easy to implement properly, hence the code working pretty much right away!