2D Collissions algorithms performance
Posted: Fri Nov 16, 2012 10:53 am
What's the best way to do square-based collisions on a bullet-fest 2D game?
Basically I need to check the next collisions:
- Player collides enemy
- player collides enemy bullet
- player bullet collides enemy
The problem here is that the game will have many objects, so i want some method to avoid thing like
That is, for's inside for's i think are unavoidable for situations where there are a group of objects that can collide with elements into another group of objects.
So what I'm asking is what is the best (most efficient) way to do this, having into account that what I'm doing could be ported to android, that is less powerful than PCs.
[EDIT]
And when i'm talking about "crowded situations" i mean "situations where there could be 20 enemies, 100 enemy bullets and 20 player bullets", those for's could be a true processor time black hole...
Basically I need to check the next collisions:
- Player collides enemy
- player collides enemy bullet
- player bullet collides enemy
The problem here is that the game will have many objects, so i want some method to avoid thing like
Code: Select all
for i,v in ipairs(playerBullet) do
for j,k in ipairs(enemies) do
print("One player bullet collided one enemy")
end
end
So what I'm asking is what is the best (most efficient) way to do this, having into account that what I'm doing could be ported to android, that is less powerful than PCs.
[EDIT]
And when i'm talking about "crowded situations" i mean "situations where there could be 20 enemies, 100 enemy bullets and 20 player bullets", those for's could be a true processor time black hole...