I guess it depends on what you’re doing now, and what you need.
What ARE you doing now?
For most of my games, I find that “bounding box” collision detection is
good enough. Most people don’t notice the inaccuracies… especially since
they’re usually in favor of the player. (If the bullet destroys the rock
even though they didn’t technically have pixels “touching,” noone will
ever complain :^) )
Bounding box is pretty much:
if (thing1_x + thing1_width >= thing2_x &&
thing1_x <= thing2_x + thing2_width &&
thing1_y + thing1_height >= thing2_y &&
thing1_y <= thing2_y + thing2_height)
{
/* they collided! */
}
That is:
if ( the right side of thing1 is past the left side of thing2, and
the left side of thing1 is not past the right side of thing2, and
the bottom of thing1 is below the top of thing2, and
the top of thing2 is not past the bottom of thing2)
then,
they collided!
If I want to give any kind of handicap to one object or the other, I just
’widen’ their bounding boxes by adding a few pixels here or there.
Note: This only works if the ‘things’ on the screen aren’t moving towards each
other at too high a ‘speed’ (eg, pixels-per-frame-in-which-you-do–this-test)
In that case, you’ll want to do sub-movement and tests, or some kind of
liney algorithm, or some other thing that rarely ever applies in the
retro-style “Atari 2600 clone” games I always write.
Good luck!
-bill!
bill at newbreedsoftware.com
http://www.newbreedsoftware.com/bill/On Tue, May 07, 2002 at 05:01:45PM -0600, mike shoup wrote:
I was wondering if anyone knows where I can find a tutorial on collision
detection in a 2D space. I realise it probably isn’t too hard, but I want to
see if their is a better way to detect collisions than what I am using.