fast algorithms

Ok I have a situation where one character must test whether they collide with any other characters or debris, so far I have done this by testing whether or not the characters rectangle intersects another character or debris’ rectangle. As you can imagine this will become very big as more characters are added into a game, so I wonder if there is an algorithm that would handle this more effectively? Any kind of link to a site or book that has other algorithms useful to game development would be nice as well.

Ty for any and all help.

What you need, is to cut down on the collisions being checked.

Here are some choices that I recommend:

  • QuadTree
  • Circle Collisions

Google Quadtrees, as they are quite abstract.

For circle collisions, change to using circles instead of AABBs.
Then do this:


float dx = this.x - other.x;
float dy = this.y - other.y;
float r = this.radiusSquared + other.radiusSquared;
if((dx*dx)+(dy*dy) < r)
{
// the objects collided. do whatever.
}

The variables should be self-explanatory

Also, just think about different ways of cutting down on the amount of checks.
Test those methods with large amounts of objects.
Compare FPS.
Implement if successful.

Hopefully you can get this to work

There are several active threads here on this very subject.

This thread has the additional benefit of linking to several others: