Why doesn't my collision detection between two Area2D objects in Godot 4 work?

1 reply · 6K views · last reply
Darkmisc
Messages
222
Reaction score
31
TL;DR
I've followed steps from a tutorial on how to set up collision detection between two Area2D objects. It's not working and I can't figure out why.
Hi everyone

I'd like to detect collisions between a circle and a floor.

I have set them up as follows:

Screenshot of the Godot 4 editor showing circle.gd open with func _on_body_entered(body) checking body.is_in_group("floor") and printing "yes", with the Node2D signal list on the right.

Godot 4 Node inspector panel with the Groups section open, showing the group named circle assigned to the selected node, with Manage Groups and Add controls.
Screenshot of the Godot 4 editor showing the floor scene tree, the floor_sprite.gd script with a _on_body_entered function checking body.is_in_group("circle"), and the Signals panel for Area2D.


Screenshot of the Godot editor showing a script tab named floor_sprite with partial code, and the Node inspector's Groups panel listing a single group called floor.
The script runs fine (it's just a circle falling towards the floor), but nothing happens when the two objects collide.

Does anyone know what I've done wrong?Thanks
 
Darkmisc said:
Does anyone know what I've done wrong?
Yes, (1) following a tutorial blindly without thinking and (2) giving up before you have tried to find the problem.

Before you add the 'if body.is_in_group' code you should test to see if the '_on_body_entered' event is firing.