Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | MaaaxiKing |
I have an object and when it was hit and has 0 hp I call queue_free()
on it. In its script there’s the _on_hit(damage)
function. In this I increase the weapon’s damage for 5 seconds (yield(get_tree().create_timer(5), "timeout"
) and after the time is out, the damage will be decreased again. But if the object is queue_free()
d, it cannot reset the damage. How should I solve this problem?
Hi! I’m not sure if im getting right the question, but can’t you decrease it manually before calling queue_free
?
p7f | 2020-06-29 14:53
I can but I don’t want to do that. I don’t care if the object still exists or not, the damage should be decreased after 5 seconds, not before, not after.
MaaaxiKing | 2020-06-29 14:56
Can you be more descriptive? Is the object a monster? It sounds to me like you are changing the weapon’s damage from within a monster object’s script, which would make sense if the weapon belonged to the monster, but not if the weapon belongs to the player. Just trying to understand what you’re describing.
DDoop | 2020-06-29 15:17
I also don’t understand. So its like when you hit someone, you make the weapon’s damage higher for some time? In that case, the timer should be on the weapon, not on the object that got hit. You can start that timer on the weapon as soon as you increase the damage.
p7f | 2020-06-29 15:23
It’s not a monster, it’s a special stone that makes the pickaxe more “dangerous” when hit hahah.
MaaaxiKing | 2020-06-29 15:30
So i would do this way. Make a set_damage(damage)
function in your weapon. Inside it you set the damage and start a timer. When the timer times out, set the damaga again to original value. Instead of using yield, i would probably use a Timer node in case you can hit multiple stones at the same time, and you dont want to the damage resets when the first timeout occured.
p7f | 2020-06-29 15:37
I concur, sounds like you are describing “feature envy” MaaaxIKing
DDoop | 2020-06-29 15:40