Godot 4.4
I’m having issues with an Area2D detecting a CharacterBody2D node. When the player approaches the Area2D node, the print statement doesn’t happen.
Here is the code I’m using in the node tree with the Area2D:
var player_in_area = false
func _on_chat_detection_body_entered(body):
if body.has_method("player"):
print("player has entered speaking range")
player_in_area = true
func _on_chat_detection_body_exited(body):
if body.has_method("player"):
print("player has exited speaking range")
player_in_area = false
Here are the node trees of the dialogue area and the player:
Player (CharacterBody2D)
→ Sprite2D
→ Camera 2D
→ PlayerCollision (CollisionShape2D)
Your area only looks for objects with a func player in it, that’s what has_method("player") means. I’d recommend giving your player a class_name so you can reference that instead.