0 votes

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.

Godot version v.3.3.stable
in Engine by (12 points)

2 Answers

0 votes

here you go:


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

by (4,010 points)
0 votes

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"):

func player_damage():
     player.heath  -= 1

func _on_spikes_timer_timeout():

func _on_spikes_area_body_exited(body):  
     if body.is_in_group("player"):                
by (438 points)
edited by
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.