Take the 2-minute tour ×

Fairly simple question that Im sure you will laugh at me for.
I have two rectangles playerRect and wall.
I have an if statement with the condition being ..

if (CGRectIntersectsRect(playerRect,wall)) {
      //handle collision here

The problem I'm having is working out which side actually hit the wall rectangle.
I need to know because then I stop te player from moving depending on which side hit.
Thanks for any help

share|improve this question
check this if u didn't stackoverflow.com/questions/3079168/… –  Bobj-C Nov 26 '10 at 19:27

2 Answers 2

up vote 0 down vote accepted

I would add some direction property to my 'Player' object. This way when you detect a collision, you just check to see which way the player was moving prior to the collision and react accordingly.

share|improve this answer

Create a CGRect for each side of your object with just a width of 1 (or height of 1 depending on the side) and look for intersections with the sides instead of the entire object. If your object is moving faster than 1 pixel per collision check, then you would check the sides in addition to checking the entire object

share|improve this answer

Your Answer


