I am working on a simple game at the moment and Im currentyly trying to do the collision. The collision is done by the usual, creat two rectangles and check if they intersect. My question is, is there a way to tell which sides of the rectangles are intersecting?? As in to know which direction one sprite is moving into the other.
Rectangle Collision
Started by walsh06, May 23 2012 11:52 AM
2 replies to this topic
Sponsor:
#2 Members - Reputation: 187
Posted 26 May 2012 - 12:30 PM
Well, surely doing checks such as:
Then in this instance rect1 is colliding to the top of rect2. I could be wrong though, these things can sometimes be deceptively simple
Another approach would be to have 1 large bounding rectangle, and 4 smaller rectangles representing his head/rhs/lhs/feet. The large rectangle would be a quick check to see if anything is likely to collide, then depending on which smaller rectangle it collides with, you make the appropriate reaction to it.
These smaller rectangle idea could be helpful for things like walking on a platform, you only want "Gravity" to stop if his feet are collding with something etc.
if(rect1.y + rect1.height <= rect2.y && rect1.Intersects(rect2))
Then in this instance rect1 is colliding to the top of rect2. I could be wrong though, these things can sometimes be deceptively simple
Another approach would be to have 1 large bounding rectangle, and 4 smaller rectangles representing his head/rhs/lhs/feet. The large rectangle would be a quick check to see if anything is likely to collide, then depending on which smaller rectangle it collides with, you make the appropriate reaction to it.
These smaller rectangle idea could be helpful for things like walking on a platform, you only want "Gravity" to stop if his feet are collding with something etc.
Edited by dAND3h, 26 May 2012 - 12:33 PM.






