开发者

Collision Detection between two rectangles

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 w开发者_如何学Pythonall rectangle.

I need to know because then I stop te player from moving depending on which side hit.

Thanks for any help

Disco


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜