Can you detect a sprite with a Area2d node

Godot Version

Question

I am trying to make my enemy take damage and the area 2d on the enemy is supposed to detect a body entering but is not detecting my sword.

func _on_hurt_box_body_entered(body):
	if body.has_method("Sword"):
		print("entered")
		player_in_attack_zone = true
		


func _on_hurt_box_body_exited(body):
	if body.has_method("Sword"):
		print("exit")
		player_in_attack_zone = false

this is not detecting this sword scene.
image

Only nodes extending CollisionObject2D can be detected by Area2D

In your case the node that’s going to be detected is the HitBox Area2D not the root Sword Node2D.

i have a func Sword() in the hit box so it should be able to detect it but for some reason its not

Looks like you’re using the body_entered and body_exited signals, but you need area_entered and area_exited, because the hitbox is an Area2D node.

image
this is still not working

Check your collision layers and masks and make sure they are correct,

Also make sure monitoring and monitorable are enabled as well.

What’s entering the signal (area) may not have method Sword, because the area may be a child of the Sword.

Put a print above the if statement too so you can get more info.

the collision and mask are both on the same layer as the enemy and sword, the monitor thing is also checked. after putting the print above the if, the player is getting detected but the sword is not
image


is this not where i put the sword func for the detecting?