TACO
April 9, 2024, 8:32am
1
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.
mrcdk
April 9, 2024, 9:07am
2
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
.
TACO
April 9, 2024, 10:19am
3
i have a func Sword() in the hit box so it should be able to detect it but for some reason its not
grulps
April 9, 2024, 10:29am
4
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.
TACO
April 9, 2024, 10:40am
5
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.
davek
April 9, 2024, 2:33pm
7
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.
TACO
April 9, 2024, 9:09pm
8
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
TACO
April 9, 2024, 9:10pm
9
is this not where i put the sword func for the detecting?