Area2D not detecting anything

i made a empty scene with just a charcaterbody2d with collision shape and an area2d with collision shape

i added this script to the area2d

extends Area2D

func _on_body_entered(body: Node2D) → void:
print(“Player has entered the area!”)

but it doesnt work, i checked that they are on the same layer and i checked that monitoring is on, but it doesnt work

That is not the correct logic for collision detection.

Layer: This represents which layer the current node is.
Mask: This represents the layers that object scans for collision.

So if they are both in the same layer. But then you change the mask to a different layer, the nodes cannnot detect the collision. For your detection to work, the ‘Mask’ set on the Area2D node should include the ‘Layer’ set for the Charcaterbody2d

my characterbody2d is layer 1 and mask 1 and so is the area2d

1 Like

OK so that doesn’t seem to be the issue.
Can you take a screenshot of your node structure and share here?

i moved the characterbody2d and area2d to my main scene
this is the node strucutre

Before running the project, can you enable ‘Visible Collision Shapes’ under Debug menu.

And send a video of where and how it should collide during runtime. Maybe it’ll tell us something.

Did you connect the signal with the function?

Here’s a tutorial about signals:

Is there a green icon on the left to this? If not, your signal isn’t connected.

i connected _on_body_entered to area2d but i dont see a green icon in the code

the function works when i put it in characterbody2d but i need it in area2d…(just to be clear the function doesnt work in characterbody2d when i enter area2d in game it just instantly works because the characterbody2d is inside itself so it counts it as body entered)

Seems like the signal isn’t connected correctly? You have to make sure to connect it from the Area2D to itself (if that’s where you want to call a function).

i connected the signal to area2d, it works now thanks

2 Likes

can you send a video of the scene (a pan around) and you walking around in the scene?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.