Topic was automatically imported from the old Question2Answer platform.
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…
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()