This is the health bar for a game I'm helping someone develop:

I want the bbcode text that displays the amount of HP left to shake when the player's HP gets below a set threshold. The problem is that because I have to constantly set the bbcode text to update the player's current health - and this resets the [shake][/shake] tag for some reason, making appear as though the text is not moving.

I haven't been able to do what I wanted yet, and have tried several different approaches to it - is this simply impossible?

This is what the local node tree looks like if this helps at all:

extends Control


# Declare member variables here. Examples:
export(int) var max_health = 20
export(int, 0, 20) var current_health = 20

export(int) var warning_lvl = 10
export(int) var shake_rate = 20
export(int) var shake_amount = 10

var text = "[center]" + str(current_health) + " / "+ str(max_health) +"[/center]"
var still = true

# Called when the node enters the scene tree for the first time.
func _ready():
	$HPC/HPBar.max_value = max_health
	$HPC/HPBar.value = current_health

	find_node("HPPercentage").bbcode_text = text	# The RichTextLabel being referenced


func set_health(hp):
	current_health = hp

	if current_health <= warning_lvl:
		still = true


func add_health(hp):
	current_health += hp

	if current_health > max_health:
		current_health = max_health

	if current_health <= warning_lvl:
		still = true


func sub_health(hp):
	current_health -= hp

	if current_health < 0:
		current_health = 0

	if current_health <= warning_lvl:
		still = true


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
	$HPC/HPBar.max_value = max_health			# HPBar is a TextureProgress node
	$HPC/HPBar.value = current_health

	if current_health <= warning_lvl and still:
		text = "[center][shake rate=" + str(shake_rate) + " level=" + str(shake_amount) + "]" + str(current_health) + " / "+ str(max_health) + "[/shake][/center]"

		still = false

	if current_health > warning_lvl:
		text = "[center]" + str(current_health) + " / "+ str(max_health) +"[/center]"

	find_node("HPPercentage").bbcode_text = text

You don't need to use RichTextEffect here. You can move the HPPercentage node itself every frame in _process() (with a random position) to achieve this.

@Calinou said: You can move the HPPercentage node itself every frame in _process() (with a random position) to achieve this. Although this is true, this is not the effect I want - I would prefer each character to move randomly; it looks much better that way

Not sure if it would help, but in Godot 3.2.2 a PR was merged to make appending effects work, so maybe it would solve the issue here as well?

@TwistedTwigleg said: Not sure if it would help, but in Godot 3.2.2 a PR was merged to make appending effects work, so maybe it would solve the issue here as well?

I will definitely have to try this out, but i can already see a possible issue with this method: I still need to remove the existing text before appending, otherwise there would be a long string of text. Unless I'm missing something crucial here, this requires me to set the bbcode to an empty string, thus resetting the animation

a year later