0 votes

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.

Godot version 3.2.3 stable
in Engine by (64 points)

1 Answer

0 votes
Best answer

You can make animation (using AnimationPlayer) to enable hitbox during exact animation frame when it should hit player.

by (1,314 points)
selected by

Ok I made a new AnimationPlayer like you said so now I am using a AnimationPlayer for the attack animations and a AnimatedSprite for the other animations. The hitbox is working perfectly as expected but now I have another problem. The attack animations are kind of laggy and jittery. Any idea on how I can fix this?

It's hard to say without video or example how it is jitters.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.