Collison Detection -_-
Posted: Sat Nov 22, 2008 3:49 am
Okay, so I've been working on my game for a little bit now, and I'm just playing around with collision detection. I have a wall (62x244). I want to have it if the player hit's it, he doesn't go anywhere (obvious?). Well, if the player (45x48) hits the wall from the left side, it makes the collision detection. If he hits the bottom, it makes the collision detection. That's all I want so far. Well, I noticed that if you hit the bottom-left corner of the wall, he can walk through it...
Hopefully I can get some help. For those of you who don't know (which I don't see why you would need to know), I'm using C++, and SDL. Alright, thanks (for future reference).
Code: Select all
// Hits the left side of the wall...
if(PlayerX + PlayerW >= WallX && PlayerY >= WallY && PlayerY + PlayerH <= WallY + 244 && PlayerX <= WallX)
{
PlayerX -= 1;
}
// Hits the top side of the wall...
if(PlayerY <= WallY + 244 && PlayerX >= WallX && PlayerX + PlayerW <= WallX + 62)
{
PlayerY += 1;
}