Godot Version
4.2.2 stable Windows 11
Question
In my player node, I have this code to detect whether an enemy or bullet is within the player’s hurtbox:
func _on_hurtbox_area_entered(other):
if other.is_in_group("enemattack") or other.is_in_group("bullet"):
if not other.get("damage") == null:
collision.call_deferred("set", "disabled", true)
iframes.start()
hurt(other.get("damage"))
print("you're taking damage!")
This works perfectly when an enemy (whose hitbox Area2D is in group “enemattack”) enters the hurtbox, but does nothing when a bullet (whose hitbox Area2D is in group “bullet”) enters the hurtbox. I’ve made sure the bullet’s damage value is not null.
Furthermore, I also have this code, in my player script as well:
func _on_interact_area_area_entered(area):
if area.is_in_group("sugar"):
area.target = self
print("grab that sugar!")
func _on_collect_area_area_entered(area):
if area.is_in_group("sugar"):
sugar_held += area.collect()
print("sugar increased!")
This is to check if objects in the group “sugar” are nearby, and to collect and increase sugar_held if they are even closer. But nothing happens, nothing even gets printed.
This is what my player scene tree looks like:
What’s the problem here? Why do objects in the group “enemattack” get detected by the player, but objects in the other groups don’t? Any help is appreciated.