How to deal with Input Event in two overlapping Area2Ds ?

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

I have created two circular Area2Ds and they use a common parent script. They both overlap each other a little bit. The issue is that when players click on the overlapped area region, undesirable results are being produced (For example one of the areas will increment correct_answer_count and other area will decrement wrong_answer_count simulatenouly. This is not desirable )

Therefore I was thinking of a way to deal with the Input event in such a way that when a click is made on overlapped area region, the user will get a message on the screen that TWO REGIONS CANNOT BE SELECTED AT ONCE. How can this be achieved ? Thanks

Have you looked into using different layers for the areas? Is there a way to prevent the areas from overlapping? Or maybe you could give us other details about the project which will help with solving the issue?

Ertain | 2023-05-14 21:04

It is not really possible for me to prevent them from overlapping as some of them represent locations that are near each other and there are quite a few of these. Here is a video showing two such areas

In the video when the overlapped area is clicked not only the correct location logic is running but also the other location is getting considered, thus executing the wrong location logic.
I am trying to work with Collision Layers but haven’t been able to achieve what I want so far.

Scavex | 2023-05-15 10:09

:bust_in_silhouette: Reply From: CassanovaWong

colloisionpolygons or collisionshapes?

i use polygons mostly and I can use all Geometry to manage something like this.

In your case, maybe something like this, where the point is the mouse position when clicked:

is_point_in_polygon ( Vector2 point, PoolVector2Array polygon )

Returns true if point is inside polygon or if it’s located exactly on polygon’s boundary, otherwise returns false.

if using shape, maybe you could use on shape entered signal from area2D…