Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | RockyXDeadman |
hello all i am trying to make my enemy attack after every 0.5 seconds but it doesnt instead it attacks really fast and constantly hence i want to use a timer and fix this. i tried using a timer and writing code on appropriate place but it did not work out i also saw godot documentation but it did not help much.
if u can help find another error here is that it doesnt detect the player until player hits him and then it works as it should but still attacks fast.
i want to know where to write the timer code in this:
here is the enemy code( i have cut and made it small and relevant):
var player_in = false
func idle_state(delta):
animationstate.travel("idle")
velocity = velocity.move_toward(Vector2.ZERO, friction * delta)
seek_player()
func attack_state(delta):
animationstate.travel("attack") #animation tree is used
velocity = velocity.move_toward(Vector2.ZERO, friction * delta)
func attack_animation_finished():
state = idle
func seek_player():
if playerdetectionzone.can_see_player() and player_in == true:
state = attack
elif playerdetectionzone.can_see_player() and player_in == false:
state = walk
func _on_attackradius_body_entered(body):
player_in = true
state = attack
func _on_attackradius_body_exited(body):
player_in = false
state = walk
Where do you start the timer in code?
Ras0922$$ | 2020-07-16 14:02