How would I implement a Spatial Hash for 2D collision?

I’ve been researching for the past week on using a spatial hash. I don’t want to use external libraries nor do I want to use a quadtree, since my game is tile-based. Any help would be appreciated.

Hi.
There is no clear answer to that. Making a physics engine is very hard. Luckily a simple collision system is a lot easier. You can search some already existing libraries and find out how they work.

Collision Grid (Github)
This library is exactly what you want. But for learning purposes, you can try to read and understand the code:D. It has some things that can be improved.

Humper (Github)
This library too uses a grid system to improve the collision check performance. It has a small code base so i recommend this too to be read.

1 Like

Yeah, I don’t want a full out physics engine since my game is top down anyways. Thanks for the reply!