Detecting 2 semi-overlapping bodies simultaneously

Godot Version

4.6

Multiple Body collision with cursor

I’ve been trying to get a good collision system for my card game going, but as shown in the image, 2 cards collide with the cursor object when at the point of overlap.

How can I solve this issue?

I have set the Mouse Filter to Stop for my card Control nodes. These are placed as a child of my individual cards which are node 2d.

I have already tried disabling cursor collision when already colliding with a body like so:

# Cursor Script
# These are connected to the respective signals
func _on_body_entered(body):
mouse_coll.disabled = true

func _on_body_exited(body):
mouse_coll.disabled = false

I’m a beginner dev and am not rlly sure what to do from here. Any help is appreciated.

What type of body is emitting those body entered/exited signals?

Area 2d

How is mouse detected using body entered/exited signal?

Areas are not z sorted and their order may randomly change from frame to frame. Better to use control node events to capture the mouse events. If you insist on using areas you may want to set Viewport::physics_object_picking_sort and possibly Viewport::physics_object_picking_first_only flags.

I’m using a custom cursor object that is an area 2d. The cards detect the cursor’s entry and perform their function. The cards themselves are control nodes however since I’m using a custom cursor object i placed an area 2d under it to detect the cursor.

Areas can detect actual mouse events. So first do away with that cursor area and capture the real mouse.

I’ve done away with the cursor object. I’m using an area under the card scene to detect the actual mouse. I’ve connected the appropriate signals asw.

Now if you enable those two flags I mentioned earlier only the topmost area should receive the event.

Sorry if this is a bit silly, but where exactly can I find those flags?

Edit: I have found out how to do this.

Simply refer to the flag in code like so:

‘‘‘

 get_viewport().physics_object_picking_sort = true

‘‘‘

Yes, set them for the active viewport like that.

I have tried applying them to the _ready function on my card object however it simply doesn’t detect my cursor at all (which is why I created a cursor object in the first place). Is there any possible reason my cursor isn’t detected despite using the appropriate signals?

Are signals properly connected?

Yes they seem to be.

Put some print statements at the start of signal handling functions to see if they’re getting called at all.

No print statement comes out. It seems that my cursor isn’t being detected at all.

Make sure that areas have input_pickable enabled. And put those prints at the very beginning, outside of that if block.

Input pickable was already enabled and I also placed the print statements outside previously.

Make sure there isn’t a control placed over the areas, consuming the events.
At runtime, you click on a card and in Debugger/Misc/Clicked Control. If some control is listed there it likely consumes the mouse events before they reach the areas as physics objects are last in the queue to get the input events.

As it seems the input does not reach my card object but instead bypasses it completely and interacts with my hand object behind it.

I have already checked that my mouse setting is set to stop on the card area 2d.

Areas don’t respect the z order, as I already mentioned. They will always get the event last even it they are “above” control nodes in the scene tree. That’s why it’s better to use controls for this.

Try to temporarily disable input for the hand by setting its mouse filter to “ignore”, and see what happens.