Many Collision checks in game loop

Started by
12 comments, last by Nicholas Kong 11 years ago

Trying researching spatial partitioning and bounding volumes.

Examples would be:

Spatial partiions: Sort-and-Sweep, 2D grid, quad-trees, binary space partitioning.

Bounding volumes: Axis-Aligned Bounding Box (AABB), spheres.

Also, keep your brute-force methods around. You'll need 'em later on to verify correctness of "all-of-the-above."

HTH.

Woah thanks for the examples! This definitely opens new opportunities for me to grow smile.png

Advertisement

Put lasers and ships to separate list. No need for checking type of object at inner loop. Can lasers collide with other lasers? If not then you are checking way too many units against each other.

True. I should put the lasers and ship separately. Definitely would clean up some unnecessary object searching in the list as well as eliminating the instance checks. Lasers won't be collide with other lasers. Thanks for the heads-up.

As others have mentioned, there are many ways to optimize collision detection. Which methods you can deploy depend on the mechanics of the game itself. Someone already brought up how lasers don't collide with other lasers. But what about enemies colliding with other enemies? From what I understand, you're creating a top-down space shoot em' up. In many games like this (and in many retro games in general) enemies don't collide with other enemies - they simply overlap and pass through each other. Because of this, enemies don't need to check for collision against other enemies. Also, will your game have power-ups you can collect? It should go without saying that these objects only need to check for collision against the player.

Someone mentioned spatial partitioning. For the type of game you're creating this is overkill. The most common method of keeping collision checks to a minimum in a top-down space shoot em' up is to create the enemies' objects during play as the player approaches where they should appear (as opposed to creating all the enemies at once when the level loads). You will also need to destroy the objects as they leave the screen. This is also a common method in retro 2D platformers and it's effects are easy to observe: have you ever wondered why enemies tend disappear when they move off screen, only to reappear at their starting point? This is why. Using this method of creating and destroying objects as needed also serves another purpose - enemies off screen will not be rendered or have their logic updated each frame, thus saving a lot of processing.

As others have mentioned, there are many ways to optimize collision detection. Which methods you can deploy depend on the mechanics of the game itself. Someone already brought up how lasers don't collide with other lasers. But what about enemies colliding with other enemies? From what I understand, you're creating a top-down space shoot em' up. In many games like this (and in many retro games in general) enemies don't collide with other enemies - they simply overlap and pass through each other. Because of this, enemies don't need to check for collision against other enemies. Also, will your game have power-ups you can collect? It should go without saying that these objects only need to check for collision against the player.

Someone mentioned spatial partitioning. For the type of game you're creating this is overkill. The most common method of keeping collision checks to a minimum in a top-down space shoot em' up is to create the enemies' objects during play as the player approaches where they should appear (as opposed to creating all the enemies at once when the level loads). You will also need to destroy the objects as they leave the screen. This is also a common method in retro 2D platformers and it's effects are easy to observe: have you ever wondered why enemies tend disappear when they move off screen, only to reappear at their starting point? This is why. Using this method of creating and destroying objects as needed also serves another purpose - enemies off screen will not be rendered or have their logic updated each frame, thus saving a lot of processing.

Right. Enemies won't be colliding with other enemies. My game will have power-ups in the future. It has been on my mind. smile.png Thanks for another heads up right now the monsters will always be within the screen. But I can certainly experiment how the monsters should exit the screen like in common arcade shooters.Thanks for the explanation for creating and destroying objects

This topic is closed to new replies.

Advertisement