followed this tutorial : https://www.youtube.com/watch?v=UlvBqz8bhCo

the guy is working mostly in 2D, i tried to apply the same method but I'm hating working with UI in godot, everytime I seem to get something right, I get 100 more wrong.

the problem I'm having is that when I hit multiple enemies, only one damage indicator shows enter image description here

so basically in the code the func _ready() animates the damage indicator making it shrinks after it appears... and the self.queue_free() deletes the damage after the animation is complete

I'm using a third person controller with a crossair, the damage shows offset to the left of the crossair, which is perfect for now... but no matter how many enemies I hit... only one damage pop up shows... even when enemies have different ammounts of defense so it should show diferent damage texts... it only ever shows the damage of the first enemy hit

enter image description here

the floating damage is called by the enemy when it is hit enter image description here

there is the full enemy.gd code https://github.com/Ceisri/Godot-Action-Combat/blob/main/Creatures/Enemies/Enemy.gd

The player calls the function that damages the enemies with :

func attack():
var enemies = hitbox.get_overlapping_bodies()
for enemy in enemies:
    if enemy.has_method("onhit"):

which is the mirrored version of the Enemy script... , it also has the function to be damaged:

func onhit(damage):
$GUI/HealthBar.value = int((health / maxhealth) * 100)
health -= (damage - defense)
staggered = true

it basically gets the (damage) from the enemy and the (defense) from the player... the opposite happens when the enemy is being hit.

so aggressor damage - victim defense = damage caused to victim

  • 2
    \$\begingroup\$ And you create them how on hit? In addition you should use the code markup instead of screenshots. \$\endgroup\$
    – Zibelas
    Commented Jun 30, 2023 at 14:10
  • 1
    \$\begingroup\$ This is still not the full code since it is missing the part where you define/ preload floatingtext. And it is still done as a screenshot and not as text. \$\endgroup\$
    – Zibelas
    Commented Jun 30, 2023 at 15:51
  • \$\begingroup\$ @Zibelas added the github but it's var floatingtext = preload("res://UI/floatingtext.tscn") \$\endgroup\$
    – Cei
    Commented Jun 30, 2023 at 17:28
  • \$\begingroup\$ I have basically zero Godot experience, but even for all that it is worth, you are saying onhit is called by the enemy when it is hit. But nowhere in your enemy script are you calling onhit on the enemy. You are calling it on the player, so when the enemy is hitting your player, not vise versa. Your action combat script has no onhit function as well. So where exactly is Enemy.onhit(damage) called? \$\endgroup\$
    – Zibelas
    Commented Jun 30, 2023 at 17:50
  • 1
    \$\begingroup\$ It is important to always have all relevant parts to answer a question. And you should take a look how to set up github for a full project, those text files are so small, loading a single web page is loading more data than all your scripts combined \$\endgroup\$
    – Zibelas
    Commented Jun 30, 2023 at 18:01

1 Answer 1


fixed it, before no matter how many enemies you hit, the first floating damage would ovveride all the others thus only the first will show.

now it shows all damage every time someone is hit.


-Get the screen size, divide by two to get the center

-Spawn the text at the center

But now it still overlaps

-Create an offset

-Spawn the text offset to the cursor with a random range of positions.

var offset = Vector2(rand_range(-20, 20), rand_range(-20, 20))
return center + offset

to use them in your game, just follow the tutorial and then add my part of code...

full script at : https://github.com/Ceisri/Godot-Action-Combat/blob/main/scripts/floatingtext.gd

now it can display as many damage indicators as possible, and all around the cursor, regardless of monitor size. enter image description here


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .