0 votes

Hey !
Im working on a tower defense game.
And I'd like some of my towers to apply a BURN / POISON effect.

I need a little help on how to structures the function...
right now when PROJECTILE hit ENEMY i start the function enemy.EFFECT()

func effect(effect_type,effect_amount,effect_time) 

Effect type : 1 2 3 4; 1 = damage over time. 2,3,4 are other system (speed debuf etc..)
Effect amount (in our case) : The total damage to deal.
Effect time : how long does it last. (in secondes)
(so i can basically take the dmg and divide it by time to know every "tick" time)

so now im here... And my challenge is the "double timer". Because one timer needs to make the effect last, let's say 8 seconds. And the other one needs to TICK every X seconds and apply the dmg.
So... 2 timers ? node timer or delta timer created directly in the script ?

Then, once the "status" is applied, if the same effect is applied, i want to reset the timer and dmg to the original stats. - this part won't be hard.

how would you proceed with the timer situation ?
Someone recommended me to create a unique scene for each debuff and give_parent to the ENEMY.

thx !

in Engine by (184 points)

If I could (and if I'm understanding this correctly), I would have two variables that kept track of time, and it only involved the usage of delta in the_process() function. I would structure it like this.

 # In the script that oversees debuffs.
 var effect_time = 8.0
 var dmg_time = 0.0

 # One counts up while the other counts down.
 dmg_time -= delta
 effect_time += delta

 if dmg_time >= 1.0:
      dmg_time = 0.0
      apply_dmg(amount) # This is calculated elsewhere.

  # End the effect.
  if effect_time <= 0.0:

If the effects are going to be applied to enemies, I would build in some kind of class to the enemies' script. But that may bring along other complications (I don't entirely know how you have your towers and enemies structured).

Hey !
Thanks for your reply.
I actually did a very similar thing in the mean time :

if statuts_1 == 0:
        var total_damage = effect_amount / effect_time #how much dmg
        for i in range(effect_time):
            statuts_1 = 1
            yield(get_tree().create_timer(1), "timeout") 
            if i == effect_time-1:
                statuts_1 = 0
                print("total_damage") ##last dmg tick.
                print(total_damage) ### apply dmg

        print("already burning")

This works great.
it avoid the "stacking" stop burning status to cumulate.
I'm blocking on one thing tho. How could i "reset" the timer when hit ?
I don't see any solution because each projectile trigger the function separately.

Do you see any solution ?

1 Answer

0 votes

I see an easy to do solution:
On hit, get rid of the old timer if there is one and apply your same logic, m i clear? :)
Good luck!

by (49 points)
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 Frequently asked questions and 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 [email protected] with your username.