Collision System

Started by
7 comments, last by Inmate2993 18 years, 10 months ago
I'm remaking the game galaga, how would i impliment a collision system? What are some approaches?
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
Advertisement
You could look here for starters....

Good luck!

Haora
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.
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.
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
Quote:Original post by EvilKnuckles666
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.


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.
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?
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
?
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
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..
Killers don't end up in jailThey end up on a high-score!
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.
william bubel

This topic is closed to new replies.

Advertisement