Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

To be clear because the title is slightly ambiguous: I understand that to check for collision detection it's (box.x > otherBox.x && box.x < otherBox.x + otherBox.w) etc.

However I'm curious about things to do after this, how can I sort of keep the player from entering the other object that they're supposedly colliding with without fully stopping them and therefore suspending them from movement?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

You would only restrict movement in that direction. In other words, let the player move left only he has not collided with a wall to his left. Let him move right only if there is no wall to his right. This way, if there is a wall on one side, the player can still back away.

You would do this by checking multiple collision points, so instead of box.x, you would check both box.x+(box.width/2) and box.x-(box.width/2).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.