0


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
Disco

StuStirling
  • 15,601
  • 23
  • 93
  • 150
  • check this if u didn't http://stackoverflow.com/questions/3079168/collision-detection-2d-between-rectangles – Bobj-C Nov 26 '10 at 19:27

2 Answers2

0

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.

Mark Adams
  • 30,776
  • 11
  • 77
  • 77
0

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

John Carter
  • 2,056
  • 1
  • 17
  • 16