How to convert my animated 2D sprites to polygons for doing physics on them

Started by
1 comment, last by leiavoia 19 years, 1 month ago
Background: 2D space game, seen from above like Asteroids. I have large number of spinning space ships (I have rendered them rotated in different angles) and environment graphics. I usually have 36 or 72 bitmaps per ship and currently about 10 ships plus lots of environment. I want much more graphics which is fast enough to do in 3D. I have pixel-precise collisions going which works great for shooting stuff. Problem: I want the game objects to have better collision responses with sliding and bouncing and rotation. The problem is that all slightly more advanced collision-response info I find work with circles, lines and polygons and I don't really have any :-) I have 32bit RGBA bitmaps... The ships are convex and many of my game objects can't be easily approximated by for example circles - they have stuff like wings sticking out all over. 1) Should I make my own editor where I can manually draw a polygon outline for each sprite (argh!) 2) Use some sort of auto tracing algorithm to automatically convert the !? How? 3) Something else that I haven't thought of? Any help very much appreciated! /Marcus
Advertisement
You may not like this suggestion, because it will kill your pixel-precise collisions, but you may want to consider putting a circular "shield" around your ships which has a radius equal to the distance from the center of your ship to the outer most pixel. That way, if your ship gets hit, you can draw a transparent circle around it to look like a shield so that collision detection still looks realistic. This also will allow you to use collision response info based on the circle that is your "shield" instead of the various shapes of each individual ship. Of course if you have some long and skinny ships, this will look less realistic. To account for that you may consider having your collision detection based on a bounding box around your ship. You could cheap this a little by having your shield be the same shape as your ship but a bit larger, with the concave sections filled in. That way the collision detection looks somewhat close, but may not be exact. I use bounding box detection in my space game. It's not super precise, but I haven't had anyone complain about it yet.
I would use polygons or circles. For asteroids though, i would definately use polygons. The problem is that you really *must* use convex polys. However, in practice, this is not a serious limitation. Most players will not be able to tell what the underlying geometry is without physically seeing it.

You can manually define a polygon per sprite, or you might try researching "convex hulls", which is like spreading a rubber band around your sprite. You would basically load each sprite and perform this algorithm on it to return the shape that best represents the sprite. The resulting shape would be your collision polygon and is guaranteed to be convex.

This topic is closed to new replies.

Advertisement