# Collision of two rectangles

**URL:** https://discourse.processing.org/t/collision-of-two-rectangles/22010
**Category:** Coding Questions
**Created:** [June 19, 2020, 10:25pm UTC](https://discourse.processing.org/t/collision-of-two-rectangles/22010 "2020-06-19T22:25:57Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![jeyeffkay](https://avatars.discourse-cdn.com/v4/letter/j/9f8e36/32.png) [@jeyeffkay](https://discourse.processing.org/u/jeyeffkay)
#### Post date: [June 19, 2020, 10:25pm UTC](https://discourse.processing.org/t/collision-of-two-rectangles/22010/1 "2020-06-19T22:25:57Z")

</div>

Hey guys,

I am corrently working on a flappy bird like game and I want to now how it is possible to detect a collusion. Currently the bird is just a rectangle. So I want to know how I in general can check if the rectangle is hitting an obstacle.

Greetings and thank you for your response  
Jeyeffkay

---

<div class="post-metadata">

### Author: ![astrogeek](https://avatars.discourse-cdn.com/v4/letter/a/e95f7d/32.png) [@astrogeek](https://discourse.processing.org/u/astrogeek)
#### Post date: [June 19, 2020, 11:28pm UTC](https://discourse.processing.org/t/collision-of-two-rectangles/22010/2 "2020-06-19T23:28:17Z")

</div>

Here’s a page from stackoverflow, examples written in Java but the algorithm will work the same:

> <https://stackoverflow.com/questions/31022269/collision-detection-between-two-rectangles-in-java>

Another page with a more general discussion of collisions between circles, rectangles, and polygons, presented in order of complexity (circles are easiest, polygons are most complex):

> **[Collision Detection - Circles, Rectangles and Polygons - Game Development](https://www.gamedevelopment.blog/collision-detection-circles-rectangles-and-polygons/)**
>
> Collision detection - using maths to find out if two shapes are colliding. This guide will focus on circles, rectangles and polygons.

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [June 19, 2020, 11:55pm UTC](https://discourse.processing.org/t/collision-of-two-rectangles/22010/3 "2020-06-19T23:55:52Z")

</div>

> [@jeyeffkay](#):
>
> … check if the rectangle is hitting an obstacle.

> **[Collision Detection](http://jeffreythompson.org/collision-detection/rect-rect.php)**
>
> An online book about collision detection using Processing.

[Studio.ProcessingTogether.com/sp/pad/export/ro.9bTfM49wCIJza](http://Studio.ProcessingTogether.com/sp/pad/export/ro.9bTfM49wCIJza)

---

<div class="post-metadata">

### Author: ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)
#### Post date: [June 19, 2020, 11:56pm UTC](https://discourse.processing.org/t/collision-of-two-rectangles/22010/4 "2020-06-19T23:56:36Z")

</div>

If you like to learn via video, this YouTube tutorial by Abe Pazos showing overlapping objects and dist() function is very good:

[![]( " - YouTube") ](https://www.youtube.com/watch?v=N5Ka4C3RVmw)

---

<div class="post-metadata">

### Author: ![slow\_izzm](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/slow_izzm/32/5637_2.png) [@slow\_izzm](https://discourse.processing.org/u/slow_izzm)
#### Post date: [June 20, 2020, 12:08am UTC](https://discourse.processing.org/t/collision-of-two-rectangles/22010/6 "2020-06-20T00:08:45Z")

</div>

in p5, but easily portable …

[![](https://img.youtube.com/vi/cXgA1d_E-jY/hqdefault.jpg "Coding Challenge #31: Flappy Bird") ](https://www.youtube.com/watch?v=cXgA1d_E-jY)

---

<div class="post-metadata">

### Author: ![jeyeffkay](https://avatars.discourse-cdn.com/v4/letter/j/9f8e36/32.png) [@jeyeffkay](https://discourse.processing.org/u/jeyeffkay)
#### Post date: [June 21, 2020, 6:58pm UTC](https://discourse.processing.org/t/collision-of-two-rectangles/22010/7 "2020-06-21T18:58:21Z")

</div>

Thank you for all of your response. I used the link from GoToLoop but I might try the rest in the future.
