Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Rectangle Collision


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 walsh06   Members   -  Reputation: 184

Like
0Likes
Like

Posted 23 May 2012 - 11:52 AM

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.

Sponsor:

#2 dAND3h   Members   -  Reputation: 187

Like
0Likes
Like

Posted 26 May 2012 - 12:30 PM

Well, surely doing checks such as:

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 Posted Image

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.


#3 walsh06   Members   -  Reputation: 184

Like
0Likes
Like

Posted 28 May 2012 - 11:21 AM

Ya I have it the first way but its difficult. And considering this is for a platformer your second idea seems quite good. Ill try it and see how it works. Thanks for the help.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS