Enemy don't get damage help pls

Godot Version

4.2.1

Question

My enimy don’t get damage (
Enemy code:

func _on_hurtbox_hurt(damage):
	hp -= damage
	if hp <= 0:
		print(hp)
		queue_free()

bullet code:

extends Node2D

var level = 1
var hp = 1
var speed = 100
var damage = 10
var knockback_amount = 100
var attack_size = 1.0

var target = Vector2.ZERO
var angle = Vector2.ZERO

@onready var player = get_tree().get_first_node_in_group("player")

func _ready():
	angle = global_position.direction_to(target)
	rotation = angle.angle() + deg_to_rad(135)
	match level:
		1:
			hp = 1
			speed = 100
			damage = 10
			knockback_amount = 100
			attack_size = 1.0
			
func _physics_process(delta):
	position += angle*speed*delta
	

func enemy_hit(charge = 1):
	hp -= charge
	if hp <= 0:
		queue_free()


func _on_timer_timeout():
	queue_free()

hurt box code:

extends Area2D

@export_enum("Cooldown", "HitOnce", "DisableHitBox") var HurtBoxType = 0

@onready var collision = $CollisionShape2D
@onready var disableTimer = $DisableTimer

signal hurt(damage)

func _on_area_entered(area):
	if area.is_in_group("attack"):
		if not area.get("damage") == null:
			match HurtBoxType:
				0: # --- CoolDown ---
					collision.call_deferred("set", "disabled",true)
					disableTimer.start()
				1: # --- HitOnce ---
					pass
				2: # --- DisableHitBox ---
					if area.has_method("tempdisabled"):
						area.tempdisabled
			var damage = area.damage
			var angle = Vector2.ZERO
			var knockback = 1
			if not area.get("angle") == null:
				angle = area.angle
			if not area.get("knockback_amount") == null:
				knockback = area.knockback_amount
			
			emit_signal("hurt",damage)
			if area.has_method("enemy_hit"):
				area.enemy_hit(1)


func _on_disable_timer_timeout():
	collision.call_deferred("set", "disabled",false

Did you connect the hurt signal to _on_hurtbox_hurt? I can’t see it in your code

Yes, signal of hurtbox was connected

im having a similar problem to this and its kinda tough. I dont know the solution, but it could be some of your conditional statements or other things. Try making it so for every step it prints 1 or a number and then you can see which step didnt work correctly and go from there

I solve problem

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.