I want to build a simulator using Game Maker in which there are many (up to hundreds) of obj_Cell, each has a radius of 10, (they don't have sprites, they just draw a circle with radius 10).

Each step, I want the cells to check around itself for obj_A to see if any obj_A is "touching" it, (has a distance less than 10 from the cell). However, since I have so many obj_Cell and so many obj_A, the most straight forward code (below) will have to be executed tens of thousands of times (number of obj_A * number of obj_Cell)

//In obj_Cell:
(with obj_A)
   if distance_to_object(other)<=10
      //do stuff

Is there any possible way to make this faster?

  • 2
    \$\begingroup\$ Have you done any research into spatial partitioning? \$\endgroup\$ – Gnemlock Jan 13 '17 at 4:00
  • \$\begingroup\$ Do you mean the idea of dividing the room into parts and assigning colliding objects in one of those parts and checking only in adjacent parts for collision? I think I understand the basic, but how would I implement such a thing? \$\endgroup\$ – user289661 Jan 13 '17 at 4:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.