How to use hitbox hurtbox calsses

Godot Version

<stable4.2>

Question

<Hi. I would appreciate if you could teach me how hitbox and hurtbox class work. I was watching this tutorial and realised hitbox/hurtbox class has been used, and wanted to try implementing to my project. However, hitbox and hurtbox does not detect anything somehow, and i have no idea why. also, i would appreciate if you could teach me how to put different variable (such as enemy damage, bullet damage for hitbox), since script will be shared among other attached nodes. also, is it really best to have hitbox/hurtbox classes rather than just simply making hitbox/hurtbox each time for each nodes(enemies, player, projectiles)

Btw, this is my current code for hitbox/hurtbox. When projectile hitbox enters enemy hurtbox, function knock_back will be called, but never take_damage()
Hitbox:

@icon("res://entities/node/HitBox.svg")
class_name HitBox
extends Area2D

@export var damage := 10

func get_damage() -> int:
	print("damage")
	return damage + randi() % 7 - 3

Hurtbox:

@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"):
		owner.take_damage(hitbox.get_damage())
	if owner.has_method("knock_back"):
		owner.knock_back()

Enemy script:


func take_damge(amount: int) -> void:
	print("take damage")
	health = max(0, health - amount)
	if health < 0:
		queue_free()
	pass

func knock_back() -> void:
	$AnimatedSprite2D.material.set_shader_parameter('flash_modifier', 1.0)
	await get_tree().create_timer(0.2).timeout
	$AnimatedSprite2D.material.set_shader_parameter('flash_modifier', 0.0)

take_damage will be never called because you’re checking if enemy has a function called take_damage but in your script is take_damge (you missed an “a”)

This is just a question of preference, use what you feel fits better for you

omg… I actually spent whole day trying to figure out what im doing wrong and it was just a misspelling. lmao. thanks.