Working on a Worms-type game, I have my objects in bounding boxes and they sit on the pixel terrain.

Currently I am able to successfully do the collision detection for objects when they enter the game by checking the middle-bottom pixel of the bounding box, if it is solid, reduce the x and y velocity to 0, other wise keep moving down at a value of gravity.

The trouble comes in when I start to move the "player sprites" as they can walk into walls and I'm not sure how to approach how to detect collision if moving into pixels, and finally how to resolve these collisions.

I need to be able to detect solid walls I cannot pass, and gradient hills where the player should "walk up".

Could you help point me in a way to do this or how it has been done in the past?


Let's say your "worm" is 100 pixels high, and his bottom edge is at 0 height. As you walk to the side, you'll find collisions (you know how to check if there's a collision, so I'm not going over that). If the pixel you're colliding with is LOWER than y + (h/4), where y is the height of the bottom edge (in this case 0), and h is the height of your worm (in this case 100), just let your worm keep walking, and adjust his height accordingly. If the colliding pixel is HIGHER than that value, stop you worm's movement.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .