0 votes

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 getoverlappingareas() returns anything before dropping. But, I do want the objects to touch on the edges. My problem is that getoverlappingareas() 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 intersectpolygons2d 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.

Godot version 3.4.2
in Engine by (12 points)

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

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.