Skip to main content
Notice removed Draw attention by Accumulator
Bounty Ended with Jimmy's answer chosen by Accumulator
Tweeted twitter.com/StackGameDev/status/890938364534423553
Notice added Draw attention by Accumulator
Bounty Started worth 50 reputation by Accumulator
edited title
Link
Accumulator
  • 796
  • 12
  • 29

Array-based tilemaps and bounding box (aabb?), how to do efficient tile collisions?

Source Link
Accumulator
  • 796
  • 12
  • 29

Array-based tilemaps and bounding box (aabb?), how to do efficient collisions?

At one point in my game I had every tile as it's own object, so that I could use standard AABB collision testing easily. I later realized this was horrible for performance and simply made my tiles be an array of numbers denoting which 16x16 segment to use.

However, this also means that I can no longer use standard AABB collision testing for tilemaps, since tiles don't have their own AABBs anymore. The first method I've tried is using hotspot collisions (per-pixel, see this page), but I'd really like to instead use some kind of bounding-box based collision testing instead of manually placing hotspots. The only methods I can think of are horrible for performance; using separate AABBs for tiles (already tried) and checking every singe pixel inside a bounding box / AABB for collision with a tile (likely even worse for performance).

What is a way that I can detect collisions using my character's bounding box while keeping my tiles simply an array of numbers, and not having a large performance impact?