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.

How can I check to see if only one side of a rectangle is colliding with another?

share|improve this question
3  
Can you be more specific? For example add some image? –  zacharmarz Mar 13 '12 at 6:14
    
Are the rectangles rotated (OBB)? or are they axis aligned (AABB)? –  Luis Estrada Mar 13 '12 at 12:46
add comment

1 Answer

by checking 2 rectangles relative speed, you can tell which sides are colliding. for example if one is going up and the other one is going down, it's obvious that only top edge of the first rectangle can collide with the second rectangle. after that check it's a normal AABB collision detection. you can also check for edges going to collide by checking rectangle position. consider two rectangles, the first one can only collide with top edge of second one only if it's y position is height than others.

share|improve this answer
    
Relative position seems cleaner. –  Byte56 Mar 13 '12 at 23:40
    
@byte56 but it needs more attention when implementing. using relative speed checking is straight forward code, while there are some special cases when you check using relative position. specially when two object are moving through each other. –  Ali.S Mar 14 '12 at 7:45
    
But it's not just relative speed. It's relative direction and speed. And when they are traveling the same direction, but at different speeds, you would have to check their relative positions anyway. I don't think relative position would be more work to implement, I think it would in-fact be less work, since there are no special conditions. It's a very straight forward check as well. My assumption is that these are AABB. –  Byte56 Mar 14 '12 at 15:11
    
@byte56 when I'm talking about speed, I'm a 2d/3d vector not just the scalar value. –  Ali.S Mar 14 '12 at 17:37
add comment

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.