how to make player invulnerability?

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

what i want to do is, i want my player wont take any damage when my timer start.

i try do it like red box, but wont work

sorry for my broken eng
enter image description here

:bust_in_silhouette: Reply From: jgodfrey

It’s a little hard to provide specifics based on the image in your post, but here’s a basic outline to manage invulnerability…

Create a variable to manage the vulnerability state:

onready var is_invulnerable = false

When you start your timer, set the variable indicating invulnerability:

is_invulnerable = true

Wire the timer’s timeout signal to a function, which will fire when the timer runs out. In that script, reset your variable so the player is no longer invulnerable:

   is_invulnerable = false

Finally, in your existing code, where the player takes damage, don’t do that as long as is_invulnerable == false. So, something like this:

if !is_invulnerable:
  # take damage...

thanks it work

potatobanana | 2020-02-01 17:11