Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | LyguN |
I have an enemy who chases the player and has a raycast2d on him to detect if the player is in attack range for the enemy. If the player is in attack range, the enemy hitbox is enabled and the player takes damage. The problem is that the enemy attack animation is too slow for the hitbox which means that the player takes damage before the animation actually hits the player. How would I go about to delay the hitbox enabling a little bit so that it times better with the animation?
Here is the attack function(its called everytime the raycast detects the player):
func Attack():
attackTimer.start()
if attackTimer.time_left < 0:
hitbox.disabled = false
is_attacking = true
animSprite.play(str(Enemy_Type)+"_Attack1")
yield(animSprite, "animation_finished")
hitbox.disabled = true
is_attacking = false
As you can see I tried to delay the hitbox with a timer but it doesn’t really work. Also I’d like to note that I am not using an animation player for the enemy so I can’t enable/disable the hitbox via animations. If anyone could tell me what I did wrong in my script or give me other methods to do this then that would be great.