Opinions on platform game actor/background collision resolving

Posted by Kawa on Stack Overflow See other posts from Stack Overflow or by Kawa
Published on 2010-06-16T19:50:05Z Indexed on 2010/06/16 19:52 UTC
Read the original article Hit count: 202

Imagine the following scenario: I have a level whose physical structure is built up from a collection of bounding rectangles, combined with prerendered bitmap backgrounds. My actors, including the player character, all have their own bounding rectangle. If an actor manages to get stuck inside a level block, partially or otherwise, it'll need to be shifted out again, so that it is flush against the block.

The untested technique I thought up during bio break is as follows:

If an actor's box is found to intersect a level box, determine where the centerpoints of each rect are. If the actor's center is higher than the level box's, move the actor so that the bottom of the actor's rect is flush with the top of the level's rect, and vice versa if it's lower. Then do a similar thing horizontally.

Opinions on that? Suggestions on better methods?

Actually, the bounding rects are XNA BoundingBlocks with their Z spanning from -1 to 1, but it's still 2D gameplay.

© Stack Overflow or respective owner

Related posts about c#

Related posts about game-development