How to make a repetitive timer, that checks every go pass?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Jakob12312

Hey there,

in my scene the player should get damage if he hits spikes. But by now the player gets the damage so often directly next to each other that he dies in millisecond.

So i want to create a timer that starts every time he hits the spikes and create damage if he still is colliding after a few seconds. And so on.

Sorry if there is misspelling in my text. My english sucks…

Thank you for every answer.

:bust_in_silhouette: Reply From: klaas

Hi,
here you go:

you have to connect to signal timeout to use the timer.

:bust_in_silhouette: Reply From: vnmk8

maybe something like this, use an area to detect player entering and exiting in “spikes area” if player is still inside spikes area collision when timer ends it’ll be hit again if player leaves area the timer will stop and player_damage() will not be executed again

func _on_spikes_area_body_entered(body):  
     if body.is_in_group("player"):
         player_damage()
    
func player_damage():
     player.heath  -= 1
     $spikes_timer.start()
    
func _on_spikes_timer_timeout():
     player_damage()
    
func _on_spikes_area_body_exited(body):  
     if body.is_in_group("player"):                
         $spikes_timer.stop()