0
\$\begingroup\$

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?

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

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).

\$\endgroup\$

You must log in to answer this question.

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