Polygon/Irregular Collision Detection Handling
IodiplinI've found countless tutorials on collision detection. All of which were helpful. Over much debate, I've decided to use polygon collision detection. I've made a utility that sets up vertices (and convertes them to line segments) and I have the code to detect if the lines are intersecting. There's one thing, however, that no tutorial seems to cover. "Now that I know they've collided, what's next?" In the past I've had many problems with this: just HOW to restrict sprites from walls and floors without allowing them to fall through, ever. Getting them to walk UP hills as they walk forward instead of stopping them completely. This is where I'm having problems. I can't even get my sprites to be stopped with simple RECT collision (using IntersectRECT). I've tried storing the sprites previous position, but I had flaws with that. Does anyone have a good solid collision detection AND handling method that I could see for reference? (NOTE: For 2D collisions only, I'm not working with 3D.) And I'm also going to be needing some seriously advanced handling on sprites that are very WIDE. For example, when the tank in my game starts going off a cliff I need it to topple over and fall. When it's going up a hill, the front end will begin to rise before the back end will. Etc. Any experiences, tutorials? Thanks.
Eric ColemanI was writing a response to this, but it's more complicated than I thought. I have a few ideas on how to do this, so I'll try to create a sample program. Of course, anyone else with ideas needs to post!
IodiplinThanks! Yeah, I now realize how complex this can really get. I downloaded a nice tutorial from GameDev (in C++ though). It's called PolyColly. Take a look for yourself if you want: http://www.gamedev.net/community/forums/topic.asp?topic_id=251638. After looking at this I see the potential in polygon collision detection, but this tutorial goes way over my head and way over the needs of my game. Unfortunately, I'm not really a math wiz, but I can be if I study something for long enough. I'll have to see how it goes. Thanks for your help.
Eric ColemanWell, the idea that I had was that the points of the bounding polygon should be used as another way to do collision detection. Instead of only detecting if something intersects the bounding polygon, also do a detection for each individual polygon point as though it's a really small circle. This would allow you to approximate the point of contact and simply apply forces to the appropriate point to rotate and move the entire sprite.
IodiplinHmm...I could probably work with that. I've heard of people JUST using the points, but I suppose using both would work out. I'll see what I can do. Thanks a lot! I'll give you feedback on how it turns out.
IodiplinI've decided I'm going to try to do a mix between your idea and the tutorial I found. As long as I can get the maths situated, this shouldn't be to difficult. Of course, there's always the hindrance that I don't know C++ very well, so this could prove very interesting, and CHALLENGING!!! Which makes it all the better [:)].