(Link to AcmlmWiki) Offline: thank ||bass
Register | Login
Views: 13,040,846
Main | Memberlist | Active users | Calendar | Chat | Online users
Ranks | FAQ | ACS | Stats | Color Chart | Search | Photo album
05-03-24 03:28 PM
0 users currently in Programming.
Acmlm's Board - I3 Archive - Programming - collision detection New poll | |
Add to favorites | Next newer thread | Next older thread
User Post
spiroth10

Paratroopa


 





Since: 01-28-06
From: USA

Last post: 6283 days
Last view: 6283 days
Posted on 01-10-07 01:46 AM Link | Quote
I've called it quits on my last project, and decided to start over on my 2D space game.

problem is, every time I try (with both SDL and Allegro) I cannot, for the life of me, get a collision detection system up and running.

I'd give some code that I've written, but that code has long since been deleted. I'm starting from scratch.

If someone could either point me out where I could learn to do basic bounding box collision in conjunction with SDL/allegro, that would be nice... I'd finally be able to make a game OTHER than a quiz game!
Black Lord +

Flurry


 





Since: 11-17-05
From: Where indians still roam...

Last post: 6285 days
Last view: 6286 days
Posted on 01-10-07 02:19 AM Link | Quote
I haven't really done any game programming at all in my life... save for some in qbasic, but I would guess it would go something like this... set up a 2D array of with an implementing a Cartesian (xy) plane. Something like array[x][y]

And then if the coordinates of any part of one object match the coordinates of another object... bam collision.

I mean, that's just my logical approach, but that's how I would approach it.
Young Guru

Snifit








Since: 11-18-05
From: Notre Dame, IN

Last post: 6290 days
Last view: 6283 days
Posted on 01-10-07 02:41 AM Link | Quote
Two years ago we did a collision detection program and the easiest way we found to implement it was to make a distance function that calculated the distance between two objects. If your objects are spherical it's really simple, call the distance function between every object and compare it to the sum of the two radii of the objects. If the distance is less than the combined radii then there's a collision. If they aren't spherical you'll probably need to do a distance and orientation function to determine what amount of distance is acceptable. Trying to keep track of every cartesian point that every object is occupying is much more tiresome than using a simple distance / orientation system. If you don't want to do an orientation system then you could break every object down into approximations of spheres (not sure how well that would work, but in theory it would get you close to the shape of any object).
HyperHacker

Star Mario
Finally being paid to code in VB! If only I still enjoyed that. <_<
Wii #7182 6487 4198 1828


 





Since: 11-18-05
From: Canada, w00t!
My computer's specs, if anyone gives a damn.
STOP TRUNCATING THIS >8^(

Last post: 6284 days
Last view: 6284 days
Posted on 01-10-07 02:45 AM Link | Quote
If you're using rectangular boxes, all you need to do is compare their positions. For each corner of box A, if its coordinates are >= the top left corner of box B and <= the bottom right corner of box B, they're overlapping. However, if your boxes aren't square, you also need to consider this possibility:

.-------. box A
| |
| |
| |
.--+-------+---. box B
| | | |
| | | |
| | | |
| '-------' |
| |
'--------------'

If you only test box B's corners, you'll miss the collision because they're all outside of box A; you need to test box A's corners against box B as well. Worse:

.-------. box A
| |
| |
| |
.--+-------+---. box B
| | | |
| | | |
| | | |
| | | |
| | | |
'--+-------+---'
| |
'-------'

You should see the problem here quickly.


(edited by Alice on 01-09-07 08:51 PM)
Guy Perfect









Since: 11-18-05

Last post: 6285 days
Last view: 6284 days
Posted on 01-10-07 03:01 AM Link | Quote
Like Young Guru said, collision by its very nature applies to distance. You can do collision checks of any shape you want fairly easily so long as it is either circular or a polygon. Just check for the distance from each of the vertices, as well as the edges that connect the vertices. I've attached an image to better describe what I'm talking about.



Attachments




(edited by Guy Perfect on 01-09-07 09:02 PM)
Sukasa

Birdo
Not quite as active as before.
Xkeeper supporter
Xk > ||bass
I IP Banned myself! Twice!








Since: 11-17-05
From: Somewhere over there

Last post: 6284 days
Last view: 6283 days
Posted on 01-10-07 08:40 PM Link | Quote
I did collision detection by checking to see which box has a lower X value and then checking to see if their X values overlap in any area, and then if so checking to see if their Y values do. if so, they are touching, and trigger a collision.
Add to favorites | Next newer thread | Next older thread
Acmlm's Board - I3 Archive - Programming - collision detection |


ABII

Acmlmboard 1.92.999, 9/17/2006
©2000-2006 Acmlm, Emuz, Blades, Xkeeper

Page rendered in 0.034 seconds; used 374.11 kB (max 455.41 kB)