How to use a TIMER in godot 3.2 ??? (NOOB HERE)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: 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):"idle")
	velocity = velocity.move_toward(Vector2.ZERO, friction * delta)

func attack_state(delta):"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

:bust_in_silhouette: Reply From: Friends-Games

Where you want to use the timer, add a timer node, and do this:


Change the number to any number that you want to use.
So you must know how long the animations are.

Then, go into the timer, click the tab in the top right that says “Node” and select “timeout()”.

Add that to your script, it’ll say:

func _on_Timer_timeout():

So there you write what you want to do when the timer ends.

If you want multiple different things, (not from the same timer) then add as many timers as you need. Do the steps mentioned above and you’ll be fine!