Currently, I have modified or deleted the taken_damage/value in the read-only VariableSettings node, and I’m stuck on creating damage display numbers.
I’ve followed a tutorial to create a simple Label that can read the taken_damage/value from my own VariableSettings node, but now I’m facing two issues:
- I can’t figure out how to read the
taken_damage/valuefrom another object’sVariableSettingsnode across objects. - I’m unsure about how to set up the trigger conditions for this.
Any guidance would be greatly appreciated!
///
Here is the current code:
extends Node2D
@onready var label: Label = $Label
@onready var variable_settings = $"VariableSettings" # Assuming VariableSettings is a sibling node in the parent
var position_tween: Tween
var scale_tween: Tween
var fade_tween: Tween
func _ready() -> void:
scale = Vector2.ZERO
# Get the taken_damage/value from the VariableSettings node
var damage_amount = variable_settings.get("taken_damage/value")
display_damage_text(damage_amount)
func display_damage_text(damage_amount: float) -> void:
# Cancel any existing animations
if position_tween != null and position_tween.is_valid():
position_tween.kill()
if scale_tween != null and scale_tween.is_valid():
scale_tween.kill()
# Set the damage text
label.text = str(damage_amount)
label.modulate = Color.WHITE # Reset opacity
# Generate random offset (X: -10 to 10 pixels, Y: unchanged)
var random_offset = Vector2(randf_range(-10, 10), 0)
# Create all tweens
position_tween = create_tween().set_parallel(false) # Sequential animation
scale_tween = create_tween().set_parallel(false)
fade_tween = create_tween()
# Phase 1: Pop effect (scale up + move up + random offset)
scale_tween.tween_property(self, "scale", Vector2.ONE, 0.2)
position_tween.tween_property(
self, "global_position",
global_position + Vector2.UP * 16 + random_offset,
0.3
)
# Phase 2: Continue moving up + fade out
position_tween.tween_property(
self, "global_position",
global_position + Vector2.UP * 40 + random_offset,
0.3
)
fade_tween.tween_property(label, "modulate:a", 0.0, 0.4) # Fade to 0 opacity
# Phase 3: Shrink (synchronized with fade)
scale_tween.tween_property(self, "scale", Vector2.ZERO, 0.4)