Detecting when two things are touching each other in 3D space can be a surprisingly difficult task. BabylonJS has its own built-in collision detection system, but it’s pretty basic and generic. I decided to write my own because I want a little more control and Ladon has some pretty specific constraints on how things interact. Also, it’s kind of a fun thing to write.
Traditionally, in shoot-em-ups, there are some expectations about what things interact with each other. Bullets don’t collide with each other, for example. Usually, the player can’t shoot enemy bullets, either. There are a few exceptions to that rule that I can remember. Checking every single object on the screen against every other object would be prohibitively expensive.
For Ladon, in the spirit of keeping it simple for MVP, I built a system that only allows circular shapes for collisions. Most of the things that you’ll be shooting at are roughly circular – enemy tiles (hexagons), asteroids (kinda spherical). I can add support for other shapes if needed.
Next, I’ll be adding a “sparse grid” algorithm for greatly reducing the number of collision checks during each tick. I looked at several approaches, including quad-trees, k-d trees, and just plain grids. There are tons of trade-offs with each approach, but a sparse grid seems to be best for Ladon. It’s just dividing the screen up into a grid and then only considering cells that aren’t empty. I love these kinds of algorithms.
Version 0.0.2.0 here.
Latest version here.