Another FInterp To Question

Seems to me like there are a lot of similar questions but I try to follow the responses but it is not working…

Ultimately I am updating my player health with a button press (For debug purposes). The HUD bar is updating with the results of CurrentHealth(Float).

When I fire the debug without the interp the number is correct. When I use the interp the results are very strange. Also, despite the bad date, the animation of the bar is not occurring.

See images.

227977-capture2.png

For things with fixed endpoints, you’re better off using Lerp. You give it the start and end and then the alpha (0-1) controls the interpolation.

So in this case it is reducing the value by half, for instance, if my alpha is set to .5 but it is not reducing the value uniformly, it just jumps the bar from value to value.

Maybe you should stick to FInterpTo. I didn’t notice your other image (Capture.png). It didn’t show up for some reason, only Capture2.png is visible. I clicked on the link tho. It looks like you’re doing FInterpTo wrong. Only use FInterpTo to set the widget health. Don’t set the CurrentHealth. And where are you calling this from? You should be either calling it from Tick or a timer. If you are doing that then you shouldn’t be changing CurrentHealth there because it’s constantly changing so the widget never catches up. You should set it once and interpolate on tick (for simplicity).

That said, here’s my response about the lerp you are doing (3.png):

You need to drive the lerp by using a variable for the alpha. It’s just doing a single interpolation at any given time so you have to alter the alpha over time to see it smooth. This isn’t hard to do though. You just keep a counter that accumulates the DeltaSeconds each tick (or timer tick) and divide that by the total time you want it to take. Feed that result into the alpha. At the end always be sure to check if it’s greater-than-or-equal to the final value you want. When it is, set the value explicitly to the final value and stop the lerping process.

Oh and you don’t want to lerp between the current and end health, you want to lerp between the start and end health. the current is the result of the lerp. That’s the key difference between lerp and FInterpTo. It’s why I suggested lerp.

So the Progress bar gets its data from ‘Calculated Health Percent inside the Player Character.’. ‘Widget Health Percent’ is the result of another tutorial I tried using where it wanted to have a placeholder for the updated Data. Deemed like a redundancy to me so it has since been removed.

Currently how this is all working (It is easier to type since my BP is a disaster right now I wanted to share the simple part of the setup):

EVENT BEGIN: Set’s the Current Health to the Max Health (100).

EVENT TICK: Set’s Calculated Health Percent (Current Health / Max Health [Clamped to Min 0 Max 100].

INPUT_ACTION Press Left Bumper: Current Health = Current Health - Damage.

So based on this, what is the easiest way to get the desired result of “tweening” the bar based on the data, in your opinion?

If you just want the bar to transition smoothly (and not the actual health) then I would just work with the widget. For something like a health drain effect, you’d want to work with the actual health value, but most damage can happen instantly. So I’d just interpolate the widget bar position to the current health value.

And you want to do the interpolate on tick.

Well this is more or less for visual aesthetic. All the damage will be calculated and interpreted in real time. Thus I would have to create a check and if the health hits 0 I would negate all of this and empty the bar instantly. It is because I intend to have a health regen and after so many seconds on inactivity it begins to refill one point per tick. Since I am doing that on tick it looks nice and smooth but that is just a byproduct of how I am doing it.

That being said, should I be doing the interp inside the binding where the bar is getting its data?

If there’s a tick event in there then it just depends on how you want to organize your code. I’d get it working in the main BP first and then see about moving it.

I would prefer to keep the hud work in the hud components. Here is what my bar percentage catcher looks like.

I haven’t done much with UI stuff so I can’t say. If it’s getting updated often enough, it should be able to drive an interp. I’m not sure about the WorldDeltaSeconds part tho. If it’s getting updated on tick then it should be OK. You can try it. It’s pretty easy to check. But like I said, get it to work in the main BP and then move it over, so you can be sure any problems aren’t related to the logic.

Definitely something missing. I can confirm it is updating per tick but the animations are instant not interpolated…I shall keep diggin.