Archived

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

revearz

Collision detection in Top-down perspective shooters

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
Thanks for the suggestions. I''ll try figuring out collisions with math using bounding spheres/boxes. When designing the enemy/weapons, will have to create their bounding boxes as well.

Share this post


Link to post
Share on other sites
If you can draw it, you know where it is. If you have a function f(x) to draw the points of your sine wave, plug in the x coordinate of the ship and see if it lies on the wave.

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