Walking in a 2d game

Started by
0 comments, last by Fruny 18 years, 1 month ago
I'm just trying to find a simple rectangle collision detection concept. I'm writing it in visual basic but I can implement anything from psuedocode, I'm just having trouble thinking of it. Currently it looks like: create test rectangle from players position intersect test rectangle with blockmap (a bunch of other rectangles) of level *this is the problem* split into two paths depending on if width of the collision, or height of the collision is greater move the player back if the corresponding rectangle dimension will not move them back past their previous position depending on which direction they were moving in (dx and dy from 1 to -1 possible) The problem is where the if splits off, if the player skims just the edge of a block rectangle it will allow them to walk into the rectangle. I know why this happens, and I could probably fix it by just making the code a bit longer, but I was just wondering if there is anything simpler I'm completely overlooking. Thanks.
Advertisement
Could you show how you're handling each case right now? I can't quite see what would cause the collision to fail like that.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement