Sign in to follow this  
BloodLust666

Collision System

Recommended Posts

Jiia    592
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 this post


Link to post
Share on other sites
BloodLust666    104
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 this post


Link to post
Share on other sites
Jiia    592
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.

Share this post


Link to post
Share on other sites
BloodLust666    104
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 this post


Link to post
Share on other sites
nife    235
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 this post


Link to post
Share on other sites
Inmate2993    222
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this