sprites collision detection

Started by
7 comments, last by kiwibonga 16 years ago
im doin a 2D space shooter game using sprites... but im unsure how i would go about with collision detection... it should be somewhat per-pixel accurate any tips?
Advertisement
How accurate is "somewhat accurate"??? If per-pixel collision is one end of the spectrum and a simple bounding sphere is the other, I'd say you have these options in between:

-single bounding rectangle
-multiple bounding rectangles
-multiple collision primitives (rectangles, spheres, triangles, etc.)
-low-resolution collision map (lower-res version of the sprite, can be 1-bit to save space)

There's going to be different tradeoffs with each, and for some of those you'd probably want to consider doing a simple bounding sphere test first before checking multiple primitives or a collision map.
well my idea was to first do a sphere collision test between two sprites if they collide id do a a collision test with a low res alpha map (aka collision map)... just as u said.... but the problem is that how do i compare the collison maps when the sprites are rotated?


the other option ive been thinking of is to predefine a "collision pologygon" for each sprite... but i havent found any practical way to define this "polygon"


and by somewhat i mean 1-4 pixels offset error....
For a collision map you'd need to determine the rotated position of each texel in the map, determine which texel of the second map you'd need to sample, then test both to see if there's a collision.

Using a convex polygon for each object might be a better idea, depending on what your sprites look like. See this or this for info on that.
It depends. In a lot of 2D shooters, particularly the "Bullet Hell" style of vertical shooters, the collision area of the player's ship is very small, even as small as a single pixel -- having segments such as the wing "invincible" actually makes a lot of sense, they're very thin and it's likely that enemy bullets would whiff high or low; that's why most shooters only register collision with some portion of the fuselage.

For enemy ships, the story is different. Most games make it relatively easy for a player's bullets to hit the ship. Also, precise collision data is used to place explosions/damage, designate "weak-points", and enemy ships often rotate. For this, a geometry-based approach is most suitable. Just make a "collision mesh" of sorts for general collision and for each weak-point.

throw table_exception("(? ???)? ? ???");

the space ships are mostly simple geometric shapes... but how would i go about determining the polygons in a flexible way?
Quote:Original post by Dragon_Strike
the space ships are mostly simple geometric shapes... but how would i go about determining the polygons in a flexible way?


Personally I'd probably make an extremely simple C# app that let's you specify the vertices of the collision geometry yourself, then dumps it to some kind of simple file. If the geometry is all very simple you could probably get away with just specifying the vertices yourself in a simple text file or XML file or something like that.

Agreed, a simple tool which lets you click on the image of the chip to define th collision-mesh is recommended.

throw table_exception("(? ???)? ? ???");

You know, this level of detail is usually not needed... Just try bounding box and bounding circle collision testing, and you'll see why... If you really want complex shapes, it's unlikely that you'll need more details than rectangular and circular areas. Testing collisions between n-gons is pretty complex... In a 2D shooter, I think we can all agree that it's just not worth the bother.

This topic is closed to new replies.

Advertisement