Godot Version
4.5
Question
So i am making a turn-based rpg and I needed to amke a text that would appear above an enemy when it is attacked, show the amount of damage dealt (or display “dodged” or “blocked” if the enemy dodged or blocked"), float down and disappear. I got it to work, but I ran into an issue. If the player cycles through turns too fast, this will result in the text getting teleported before it can finish the animation cycly, so it ends up looking bad. I’ve tried using duplicate() to make the node leave a clone instead of doing the script itself but i just can’t figure out how to do it. Could someone please help me fix this problem with the duplicate() or tell me about any other way to do it? Here is my current, working code.
extends Label
var enemy = []
var hero = []
var speed = 50
func _ready():
text = "no"
for i in range(1, 9):
enemy.append(get_node("/root/Battle/enemy_team/Enemy" + str(i)))
hero.append(get_node("/root/Battle/player_team/Hero" + str(i)))
func _on_current_turn_attack_message_hit(target, damage) -> void:
if target <= 8:
global_position = enemy[target-1].global_position
show()
text = str(damage)
speed = 50
await get_tree().create_timer(3).timeout
hide()
else:
global_position = hero[target - 9].global_position
show()
text = str(damage)
speed = 50
await get_tree().create_timer(3).timeout
hide()
func _process(delta: float) -> void:
#while speed >= 0:
position.y -= speed*delta
speed -= 20*delta
func _on_current_turn_attack_message_dodged(x) -> void:
text = "Dodged"
speed = 50
if x <= 8:
global_position = enemy[x - 1].global_position
show()
await get_tree().create_timer(3).timeout
hide()
else:
global_position = hero[x - 9].global_position
show()
await get_tree().create_timer(3).timeout
hide()
func _on_current_turn_attack_message_blocked(x) -> void:
text = "Blocked"
speed = 50
if x <= 8:
global_position = enemy[x - 1].global_position
show()
await get_tree().create_timer(3).timeout
hide()
else:
global_position = hero[x - 9].global_position
show()
await get_tree().create_timer(3).timeout
hide()