#Can't detect area 2D collision

1 messages · Page 1 of 1 (latest)

edgy oyster
#

I'm in v4.1.1, and I can’t detect area collision 2D from two CharacterBody2D’s, this is the code which is attached to the first CharacterBody:

func _on_area_2d_area_entered(area: Area2D) → void:
get_tree().quit()

(the get_tree().quit() is a placeholder to know if it works)
I am trying to make it so that only one CollisionShape2D is a child to an Area2D while other CollisionShape2D’s are not.

And is it a problem that in the second CharacterBody2D without the script attached to it isn’t a child node to a Area2D but instead is just a CollisionShape2D?

I have both the Area2D in the first character and the CollisionShape2D in the second character in groups.

I also have the CharacterBody2D’s in separate collision layers while the area 2D is in both collision layers, this is because I didn’t want them to collide but instead just phase through each other, while still detecting is that Area2D has collided with the other CollisionShape2D.

cursive loom
#

Can you show the tree structure of the CharacterBody2Ds and Area2Ds? Or the general scene.

To start, each CharacterBody2D needs a CollisionShape2D as a child in order to detect collisions. Likewise, each Area2D needs its own CollisionShape2D.

barren yarrow
#

Did you connect the correct area2d signal to the right characterbody script func? When characterbody2d enters an area, the area2d will emit the body_entered(body) signal, so you should connect that signal to the characterbody2d func on_body_entered(body).