I am trying to set up a default hitbox and hurtbox template as in a youtube guide.
The guide uses godot 3 and I´m using godot 4. So i need some help how to do this in Godot 4.
The main issue are with how connect() work in godot 4. I have tried some variants but not found a working solution so far.
I get 3 error codes, 2 of the saying that i cannot use string in connect() and the last is when having self inside the connect()
The code so far are:
class_name MyHurtBox
extends Area2D
func _init() -> void:
collision_layer = 0
collision_mask = 2
func _ready() -> void:
connect("area_entered", self, "_on_area_entered")
func _on_area_entered(hitbox: MyHitBox) -> void:
if hitbox == null:
return
if owner.has_method("take_damage"):
owner.take_damage(hitbox.damage)