Trying to make a damage cooldown for a 2d plateformer

Godot Version

4.2.2

Question

`so the player has 3 health. when the player collides with the enemy, he gets damaged by the enemy and maybe damaged another time instantly. so i just want to implement a simple cooldown that lasts around 1.5 seconds’

You’re probably going to want to look at Timer and signals.

1 Like

As said @slartibartfast , use a timer.
When the player is hit :

  • remove one health point
  • set the player invicible
  • start the timer

When timer ends :

  • set player hittable again
1 Like

how do you make a player “invincible” because when i disable the collision the player just falls off the map
and sorry if i sound dumb or anything, its my 3rd day in programming and thank you for your precious time

You can do it in different ways:
For example, you can create a flag can_be_hit and in your hit function, check if the player can be hit before computing the damage, when the timer times out it set the flag back to true and the next hit is accounted for.

You can set different collision layers for different use cases, so the hit be done on layer 2 and you disable only that layer: Physics introduction — Godot Engine (stable) documentation in English

See what works better for you

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.