# Collision System

This topic is 4986 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm remaking the game galaga, how would i impliment a collision system? What are some approaches?

##### Share on other sites
You could look here for starters....

Good luck!

Haora

##### Share on other sites
I would just use rectangles, unless you're doing this for a learning exercise. If so, perhaps ray vs primitives for bullets vs ships? You could also use ray vs polygons or primitive vs polygons for extreme accuracy.

##### Share on other sites
Well, as far as now, i'm going to use rectangles for everything: ships, bullets, terrain. Can anyone show me an example to where i can just use one call to CheckCollision() and it'll scroll through all ships and sees if any is colliding.

##### Share on other sites
Quote:
 Original post by EvilKnuckles666Well, as far as now, i'm going to use rectangles for everything: ships, bullets, terrain. Can anyone show me an example to where i can just use one call to CheckCollision() and it'll scroll through all ships and sees if any is colliding.

The easiest way to manage it is not to have a CheckCollision function that does all collision checks. The easiest way would be to loop through every object, move it, animate it, then check it's collision against any potential dangers. In Galaga, the player's enemies cannot hurt each other. That means all sprites except the player only check for collisions with the player and the player's bullets. But I don't see much harm in ignoring that if you want your version to be different.

Terrain would be a bit different. It depends on how you're going to set it up, but you almost certainly don't want to loop through every section of it to check collisions. Just find the cells that the objects overlap and test those.

##### Share on other sites
I think that i'm going to use the "circle collision" approach, that way i can just use the distance formula and see if that's less than the radius of the 2 objects added together.

So, instead of checking EVERYTING, just pretty much have the player check the collision against the enemies, bullets, and terrian, and have the enemies check their collision against the players bullets?

?

##### Share on other sites
Well this isn't just for collision detection, but since you mentioned "instead of checking everything", I would also suggest a quadtree or octree (depending on your dimensions) to minimize the amount of checking to perform (and it can also minimize the amount of objects to render).
There's a couple of articles about the trees here on GD, but there's also a lot of topics about them, so you shouldn't have any trouble finding relevant information about them..

##### Share on other sites
Since its galaga, you don't have much to worry about, but what you would do is check if the rectangles of objects overlap, and then maybe check the pixels too, but thats not very neccessary unless you're anal retentive about these sort of things. So, you have maybe 20 to 30 sprites on screen at any time, this form of system would require you navigate through the lists so many times to figure out which rectangles overlap and what to do about it. That'd make 210 checks or a O(n(n-1)/2) if I'm not mistaken? Not the best system, but for sprite games, its effective.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 12
• 14
• 10
• 11
• 13
• ### Forum Statistics

• Total Topics
634096
• Total Posts
3015483
×