I’m trying to create a smooth health bar and a buffer that can be upgraded. When upgrading, the bar will grow and also increase the float value of the health.
In the start of the video I use debug keys to increase/decrease health and that works as intended where you can see the slighlty lighter health bar (the buffer) moving first and the other catching up
The problem occurs as soon as I upgrade, the main bar (deep red) value is really low
The main tick event is where the logic seems to be failing
All the divisions by 100 seem unnecessary. The TargetHealth value isn’t a percentage (you need to divide by the max for that, not 100). But that’s not the issue.
With just one upgrade, you’d get something like in the video, but not sure what the “Get Upgrade Progress” values are for the first and second level.
I’m gonna leave the division by 100 out since it doesn’t change anything. If level 1 was 1000 and level 2 was 10000, then TargetHealth will still be at 1000 after the upgrade. That’s 10% of 10000. So the health bar will go down.
Like I said, I don’t know what the level values are. I also don’t know why it went down to zero. It’s as if the levels kept going up, but GrowHealthBar was only called once. Then this would cause the range to increase to almost infinity. So it’s not actually going to zero, it just looks that way because the max is getting really large. Do you have a timer you forgot to remove the loop checkbox or something?
I’d print a message every time the level goes up. Can we see the upgrade code or BP? What’s the level values?
I take it back. TargetHealth not being a percentage IS a problem. You’re using it as a percentage in FInterpTo nodes. That’s not gonna work.
If you want TargetHealth to be a percentage, you need to divide by the value of GetUpgradesProgress, not 100. Unless the value you’re using for TargetHealth is 0 to 100 only.
Either way, the normalize nodes no longer makes sense. I think you can just remove them. Those maximums aren’t percentages. If they were, they’d always be 1 anyways regardless of the level.
The levels are set in a data asset for the upgrade. Reallt I’d want the health bar to work regardless of these values and how many indexes there are. Some upgrades could have 10 indexes with the values starting at 100 going to 2000 for example.
The bar doesn’t work properlyat all currently, very jittery and has some weird jumps maybe because I removed the normalize node? In the vid you can see a print screen that returns the current health. When I upgrade it will fill te health to max
Yeah, you’re mixing up percentages and values. Here’s one possible solution. We need to divide by the level value to get the percentage and that’s what we do before setting the percentage on the progress bars.
An issue here is that when you upgrade, you won’t get the extra health. So you’ll have to manually add the difference in health between levels (120-100) as one possible solution.
edit: Also, the range of TargetHealth is now from 0 to the Level Value. So for level 2 (index 1), it would be from 0 to 120.
If you want to pass in percentages in UpdateHealth (0 to 100), then you’ll have to divide by 100 and multiply by the level value before setting the variable TargetHealth. No other changes necessary.
Thats absolutely perfect, thanks for the graph and the explanation. The buffer works flawlessly even when setting the health values per upgrade to extreme values