How do I detect areas that touch but don't overlap? SOLVED

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By merthurian

I am building a drag and drop editing system. The objects that I’m moving are Area2D with CollisionPolygon2D nodes. The polygons are very simple and every point’s position consists of whole numbers. Also when I move the objects, I use ceil on their x and y positions to align everything with a 1x1 grid.

I don’t want these objects intersect, so I check if get_overlapping_areas() returns anything before dropping. But, I do want the objects to touch on the edges. My problem is that get_overlapping_areas() returns ares that don’t overlap but do touch.

How can I get around this?

My solution:

I have since solved the problem like this:

When placing a shape, I check to see if there are any overlapping areas.
If there are, I take the returned polygons and use intersect_polygons_2d to generate the intersecting areas.
Then I check to see if the combined area of these intersecting areas is zero.

This kills two birds with one stone. I now know if the shapes are overlapping or just touching.

May I suggest clicking on “Answer” and putting your solution there.

Ertain | 2022-02-10 06:26