Hi again.
One quick question about 2d collision detection...
In most cases it's rectangles that are used for collision detection in 2d. I hadn't even known of another method before I read the collision detection topic on this board. The method described in there had to do with circles.
Now i'd like to know if there are any other methods to do collision detection in 2d?
One more question: What will i have to do, if i have a very unregular sprite and want to check for collisions with this one? By unregular i mean if you use a single rectangle which covers the whole sprite, there will be a lot of "free" space in this rectangle which does not represent pixels of the sprite. So in this single rectangle there will be a lot of space which actually shouldn't be used for collision detection because it does not represent the sprite. Will i then have to seperate the sprite into a few smaller rectangles and check for collsion with these?
Posted on 2001-12-18 11:37:38 by darester
Hi !

If you want to check very unregulary sprites for having collide you can use monochrome-bitmap-masks of the sprite and the near area. But due the the size of the sprite this could be time-expensive !

What you have to do is simply make an AND-operation between the two masks. If both masks have a zero at those places, where no pixel of the sprite/background is placed, your objects don't have collide if there isn't any 1-result !




-------------- -------------- --------------
|............| |oo.........o| |............|
|....X.......| |oo........oo| |............|
|...XXX......| AND |ooo......ooo| = |............|
|..XX.XX.....| |oooo.....ooo| |..11........|
|............| |oo........oo| |............|
-------------- -------------- --------------
(Sprite) (Background) (CollisionCheck)



At the example above the pixels where this AND-operation results in '1' collsion takes place.

For big sprites its better to tile the object in small pieces, if you can't make regular aproximations. And in most cases collision tooks only place in borders area.

Greetings, CALEB
Posted on 2001-12-18 14:03:12 by Caleb
Thanks for your reply.
Everything is clear to me. Only this one isn't:
"For big sprites its better to tile the object in small pieces"?
Do you mean the technique i was talking about? I mean seperate the whole sprite into a few rectangles and use these rectangles for collision detection?
Posted on 2001-12-19 05:59:00 by darester
Another technique is to represent objects as polygons. Collision detection is then a matter of checking to see if the edge lines of any polygons cross. As you can see in the picture.

Also small fast moving objects such as bullets can be expressed as a single line representing the distance they moved in the last frame, this allows you to calculate if they passed through any object and therefore what they hit.
Posted on 2001-12-19 07:04:47 by Eóin