Sign in to follow this  
Dragon_Strike

sprites collision detection

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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....

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this