Archived

This topic is now archived and is closed to further replies.

Collision detection in Top-down perspective shooters

This topic is 4981 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I''m thinking of programming a top-down perspective shooter like Ikaruga and 194x series. I''ve come across some stumbling blocks when thinking about collision detection. If the player''s bullets can be of any shapes and sizes, how would I detect collision between the player''s bullets and the enemy? For example, if the player''s weapon shoots out a laser that has a shape of a sine wave, how would I detect if that laser intersects any enemy ships. Any thoughts? I was thinking of something like: Rendering player''s weapon fire into some buffer B ( stencil, maybe? ) For example, the buffer will have the value 1 if the weapon fire is in that position For each enemy Copy buffer B to BTemp Render enemy to buffer, BTemp. Ideally if enemy is rendered in that position, we will increment by 1. If there is a value in BTemp > 1, then there is a collsion. Not sure how the above will be accomplished but will try to study up if the idea sounds like it''ll work.

Share this post


Link to post
Share on other sites
That sounds a little bit too complicated. Do it with maths instead. You know where the bullets are and you know where the enemies are. You also know the shape of the bullets and the enemies. It''s just a matter of calculating wheter they intersect or not. How this is done depends of what kind of shapes you''re dealing with.

Share this post


Link to post
Share on other sites
And don''t be too afraid of taking some shortcuts if the maths is too complicated. For example, if the laser fires in a sinus-wave but the amplitude of the wave is relatively small then you can probably get away with just using a rectangle that bounds the sinus wave...

shmoove

Share this post


Link to post
Share on other sites
Or have several individual bullets moving in a sine pattern, and use a particle trail for the streak. A point (bullet) to bounding sphere or box should be fine in most circumstances. Just define more points as more accuracy is needed.

Mark
Cornutopia Games
http://www.cornutopia.net
Sound Effects For Game Developers
http://www.indiesfx.co.uk

Share this post


Link to post
Share on other sites
If you''re so inclinedyou can do it the way I did it, which is pixel-perfect collision. Alot of my ships are kinda like a cross (image body + wings), and suqare/circle didn''t really work well, so I did this instead:

When I load my sprites, I also run them through a functio that creats a bit-mask of if there''s somethign there or not. I would scan through the sprite, and if there was color there, I''d put a 1 in the bit-position and shift my mask. If there was no color, I''d put a 0.

Then, I''d do square collision on the objects, and if they intersect, I''d over-lapp the bit-masks, and if there were any with 1''s at th same spot the collided.

If you know how to make the bit-masks (use 1 bit per pixel), then you save alot of memory.

If you''re REALLY interested, send me an email and I''ll give you the source.

Nutts

Share this post


Link to post
Share on other sites