(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-18-24 02:50 AM
0 users currently in Programming.
Acmlm's Board - I3 Archive - Programming - collision detection
  
User name:
Password:
Reply:
 
Options: - -
Quik-Attach:
Preview for more options

Max size 1.00 MB, types: png, gif, jpg, txt, zip, rar, tar, gz, 7z, ace, mp3, ogg, mid, ips, bz2, lzh, psd

UserPost
Sukasa
Posts: 2001/2068
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.
Guy Perfect
Posts: 431/451
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.

HyperHacker
Posts: 4708/5072
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.
Young Guru
Posts: 246/279
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).
Black Lord +
Posts: 246/273
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.
spiroth10
Posts: 122/145
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!
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.003 seconds; used 351.88 kB (max 391.98 kB)