Hurt and Hit boxes tempporary disabling

Godot Version

4.2

Question

Just started new project and only got player,enemy, hitbox, and hurtbox scenes.

From HurtBox
#collision.call_deferred(“set”,“disabled”,true)
#timer.start()collision.call_deferred(“set”,“disabled”,true)timer.start()

if area.has_method(“tempDisable”):
area.tempDisable()

If i only run with the commented part and comment the other two the character only takes damage once and never again.

If i leave it as it is i continuously take damage as per timer set in hitbox(every 0.7 sec).

My question is why does disabling collision in hitbox works but not in hurtbox?

Already checked timer, collison works in all ways:

Player → HitBox and Enemy → HurtBox and Player → HurtBox Enemy-> HitBox

And Both having both Hit and hurt box

HitBox

extends Area2D

var damage = 1

@onready var collision = $CollisionShape2D

@onready var time = $Timer

func tempDisable():

`collision.call_deferred("set","disabled",true)`

`time.start()`

func _on_timer_timeout():

`collision.call_deferred("set","disabled",false)`

HurtBox

extends Area2D

@/onready var collision = $CollisionShape2D

@onready var timer = $Timer

signal hurt(damage)

func _on_area_entered(area):

if area.is\_in\_group("attack"):

	if not area.get("damage") == null:

		#collision.call\_deferred("set","disabled",true)

		#timer.start()

		if area.has\_method("tempDisable"):

area.tempDisable()

		var damage  = area.damage

		emit\_signal("hurt",damage)

func _on_timer_timeout():

collision.call\_deferred("set","disabbled",false)

Player and enemy have some basic movement only with

func _ready():

`hitBox.damage = Damage`

and

func _on_hurt_box_hurt(damage):

`Hp -= damage`

`print(Hp)`

Do you call a method to re-enable the hurtbox when the timer finishes? I see you have that in hitbox, but there’s not an indication you have that in hurtbox too…

2 Likes

Its there on hurtbox
on timer timeout
I realized that i have double ‘b’ on “disabled” and thats why it wasnt working.

Ahh, that’d do it! I don’t know how I didn’t catch that, whoops [^^']