Collision response with area

Hi,

I’m creating a 2d side scroller and I’m planning to use the area class to create bounding areas for the player and other objects. Right now I’m using the rectangle class for simplicity, but its a little too inaccurate for my game. I need help finding out where to move the player once its bounding area intersects another objects bounding area. With the rectangle class, I got width and height of the rectangle of intersection, and, depending on which was greater and the player’s current velocity, I could determine in which axis to move the player to to get out of the intersection.

Thanks

Well you could still use Rectangle’s if you want. Instead of determining it all mathematically, you can do it like this:

In whatever collided method you have for testing, have it return a list of some kind that contains all collisions that occured. This way you can have different cases for colliding up, down, left, or right. (like in Mario, for instance, colliding down on something means it’s dead, whereas left or right means you are dead) Now, instead of using a single rectangle for testing, use four, one for each direction. The up rectangle should be the character’s (x,y-5,width, height/2) so that it has a slight buffer zone (5 pixels) and tests all upward collision. The other directions are the same way. You can experiment with different buffers for more accuracy or ability.

(I usually create constant int’s called UP, DOWN, LEFT, RIGHT, then put them in the list if each kind of collision occurs, and test for them again later)

This method works just fine, although I’m sure it’s a little inefficient. I made a Mario clone a while back where I was originally using coordinate testing (like you), but that created problems which immediately went away when I converted it to this method.

Thanks for the idea, but I still don’t know how to do collision response for the area class.

Thanks