Right now I'm working on an as2 project that requires a large number of bullets and enemies to be present on the screen at any given time. The problem is that for each bullet to collide properly I must loop through every enemy to see if the distance is within bounds. Looping through every enemy for every bullet every frame is really adding up and my frame rate is taking a hit. Is there some other method of doing this type of check?
1 Answers
The best method I've used for this type of collision is a binary tree method.
You want to start by creating an external shell for the enemies that will contain all enemies, each frame the bullets check to see if they are colliding with the shell using a simple hit test. Then you need to start dividing up the enemies into sub-shells, the main shell will contain two shells and each of those will contain two shells and so on. Then once you check to see if the bullet has hit the primary shell you check to see if it has hit sub-shell-1 if it has you have just eliminated half of the possible enemies. Then you move on to see if it has hit sub-shell-1-1 if it has not then it has hit sub-shell-1-2 no need to check, and once again you have eliminated half of the current possibilities with only one hit-test.
:)

- 46
- 2
-
This sounds like exactly what I need. I'll try to work on the implementation tonight, thanks! – user1621941 Aug 24 '12 at 09:51