0 votes

Any ideas how to make numbers that appears upon enemy and disappear when it takes damage
Here is an example what i want to make https://www.youtube.com/watch?v=ta7lyqqPRXY

Godot version v3.4.4
in Engine by (24 points)

2 Answers

+3 votes

There are lots of ways you could do this. Here's an outline for one...

  • Add a Label or RichTextLabel as a child of your enemy
  • Set the visibility to False
  • Using either an AnimationPlayer or Tween, adjust all of the label properties you want over time (visibility, scale, rotation, position, ...)
  • When the enemy takes damage...

    • Set the text / bbcode_text property of the Label / RichTextLabel to the value you want to display
    • Start the AnimationPlayer / Tween to animate the various properties as needed.
by (16,814 points)
edited by

Good suggestions. Also, avoid animating the font size (use the scale instead as suggested by Jgodfrey). From experience, every time you change the font size it will save the resource changes to the disk and potentially lag your game.

so here what i made what i think you told me to do
here is a video with short example of what i made:
https://www.youtube.com/shorts/v0RfmWZ3jhQ
There is two functions one for displaying damage when i click on enemy another for passive damage, but as you can see text appears only once per click. How to make new instances of text per click and remove them after animation is finished?
Here is a code of how i calling animation

func playClickdmg(dmg):
    $Area2D/AnimationPlayer.play("RESET")
    $Area2D/AnimationPlayer.play("text floating ")
    $Area2D/AnimationPlayer/DamageLabel.text = "your dmg = " + str (dmg)

func playPassdmg(dmg):
    $Area2D/PasiveDamageAnimation.play("RESET")
    $Area2D/PasiveDamageAnimation.play("damage floating")
    $Area2D/PasiveDamageAnimation/PassiveDamageLabel.text = "pas damage =" + str (dmg)

I'd probably set up a dedicated scene explicitly for showing this animated damage value and then just instantiate it, position it, and start it wherever it's needed. Further, I'd just have the scene destroy itself when the animation finishes.

For example, your scene could be setup like this (Damage.tscn)

Node2D
   Label
   AnimationPlayer

And, the Node2D could have the following script:

extends Node2D

func show_damage(damage_val):
    $Label.text = "Damage = %s" % damage_val
    $AnimationPlayer.play("damage")
    yield($AnimationPlayer, "animation_finished")
    queue_free()

Note, that yield() followed by queue_free() will cause the scene to destroy itself when the damage animation finishes playing.

Then, just instantiate the damage scene, position it as needed, and call the show_damage(). For example, this places a new instance at each mouse-click position and passes in a random damage value.

extends Node2D
var damage_scene = preload("res://Damage.tscn")

func _input(event):
    if event.is_action_pressed("click"):
        var pos = get_global_mouse_position()
        var d = damage_scene.instance()
        get_parent().add_child(d)
        d.position = pos
        d.show_damage(randi()%100+1)

Then, just season the underlying animation to taste. You could animate visibility, scale, rotation, position, color, ... Whatever you need.

Thank you very much, you helped a lot

0 votes

Since Godot 3.5, you have the node Label3D which let's you place text in a 3D world:
https://youtu.be/NjIJm2jax68?t=180

by (83 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.