Search code examples
c++directx2dcollision-detection

Better way to check game objects collisions


guys! I have a problems with processing collision of game objects (with other sizes). My algorithm is:

for (Array<GameObject*>::iterator it = objects.begin(); it != objects.end(); it++)
{
   RECT objRect = (*it)->GetBoundingBox();
   for (Array<GameObject*>::iterator it2 = object.begin(); it2 != object.end(); it2++)
   {
      RECT objRect2 = (*it2)->GetBoundingBox();
      IntersectRectangles(objRect, objRect2);
   }
}

Yes, that is works fine. But it works very slow. I have a idea (check only nearby objects to object), but that means more and more iterations. Maybe the better way is exist?


Solution

  • You can divide game world into some big zone, and check collssion of game ojcects in one zone just. This is a basic method.