<hurtbox class works perfectly fine and enemies takes damage whenever collided with hitbox. However, the console prints an error Error calling from signal 'area_entered' to callable: 'Area2D(HurtBox.gd)::_on_area_entered': Cannot convert argument 1 from Object to Object
@icon("res://Entities/node/HurtBox.svg")
class_name HurtBox
extends Area2D
func _ready() -> void:
connect("area_entered", Callable(self, "_on_area_entered"))
func _on_area_entered(hitbox: HitBox) -> void:
if owner.has_method("take_damage") and hitbox.is_in_group("bullet"):
owner.take_damage(hitbox.bullet_damage()) #Enemy Take Damage By Bullet
I believe it doesn’t like the type specified, it cannot convert every object that enters the area from Area2D to HitBox. Best to use an if statement to deduce the extended types
func _on_area_entered(hitbox: Area2D) -> void:
if hitbox is HitBox:
if owner.has_method("take_damage") and hitbox.is_in_group("bullet"):
owner.take_damage(hitbox.bullet_damage()) #Enemy Take Damage By Bullet