I have a floating text node (parent: node2d, child: label) that basically pops up when bullet hits the target. The enemy in this case spawns these texts to indicate the damage done to it.
public void OnHit()
{
var floatingText = floatingTextScene.Instantiate<FloatingText>();
floatingText.Text = 50.ToString();
AddChild(floatingText);
}
The problem is that the enemy's rotation is affected by players position. As well as the enemy's scale Y is changed to flip the enemy depending on players position.. Together with the enemy scale and rotation - floating text is also affected.
Is it possible for the floating text to not have the scale and rotation affected by the parent nodes modifications, but keeping the relative position to enemy's pivot?
Basically I want the floating text to live it's own life but sill be pivoted to the center of the enemy.
I am using the _Ready function in combination with Tweens to animate the floating text
public override void _Ready()
{
var label = GetNode<Label>("Text");
label.Text = Text;
label.Scale = new Vector2(0.3f, 0.3f);
var MoveSpeed = 100f;
var finalPosition = Position + new Vector2((float)GD.RandRange(-1f, 1f), (float)GD.RandRange(-1f, 1f)) * MoveSpeed;
var creationTween = CreateTween();
creationTween.TweenProperty(label, "scale", new Vector2(1, 1), 0.2f).SetTrans(Tween.TransitionType.Bounce);
creationTween.Parallel().TweenProperty(label, "position", finalPosition, 0.2f);
creationTween.TweenProperty(label, "modulate", new Color(1, 1, 1, 0), 0.4f);
creationTween.TweenCallback(new Callable(this, nameof(OnFadeOutComplete)));
}
private void OnFadeOutComplete()
{
QueueFree();
}
One of the solutions I though about is just overriding the Scale to and Position on every frame in _Proccess
function, but
a. it sounds like an overkill for such a simple task
b. this will most likely mess up with the tween'ing logic (since it also changes some of the values)
therefore I think the best solution would be to isolate the floating text from the parent's modifications. The question is how? I was thinking about spawning texts on the same level as parent node, but then I guess the text will still be affected by other logic above that which could lead to problems in the future. Should I just spawn labels right under GetTree() top-most node? So.. ideas/solutions are welcomed.