# very simple 2D collision detection?

This topic is 4997 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm looking to write a collision detection system for a cheap 2D scroller game. So far, I've got an entity that has a bounding box which consists of ints for top, left, bottom, and right. Rectangular bounding boxes are all I'm going to need. And thats about as far as I've made it so far. I need help with the actual "collision" part now.

##### Share on other sites

Hmmmm? I think collision between two axis oriented bounding boxes (that is: rectangles) is the simplest thing on earth :-)

In my last techdemo I've done it that way:

// single pointstruct TScrPoint {  int x, y; };// rectangle defined by:// v1: left down vertex// v2: right up vertex struct TRectangle  {  TScrPoint v1, v2; }; // returns true if they overlap// you may wish to change ">" and "<" to ">=" and "<="// you should be able to figure out how does it work :-)// just draw two rectangles on paper...bool RectanglesOverlap(const SC :: TRectangle & _first, const SC :: TRectangle & _second) {  return ( (_first.v1.x < _second.v2.x) && (_first.v2.x > _second.v1.x ) &&           (_first.v2.y > _second.v1.y) && (_first.v1.y < _second.v2.y) ); }

IMHO the hardest part is collision response...

Anyway, I would suggest visiting:

2d game tutorial
Jump n run

##### Share on other sites
Thanks man. Helped quite a bit.

##### Share on other sites
Whats with the "SC" thing BTW? Its defined in one of my AGB libraries as an int under "General Input/Output Control Structure."

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 14
• 46
• 22
• 27
• ### Forum Statistics

• Total Topics
634047
• Total Posts
3015232
×