How can i create a function that would update a health variable smoothly?
Good evening, I am trying to create a function that would update a health variable depending on a damage value. My problem is that I can't figure out a way to make the variable update smoothly inside a function.
Because we can't use timelines and delays in functions I am stuck, I really want it to be handled in a function to make it simple and also because I would be able to call it multiple times like for example if my player takes a hit of 20points, while the health goes down to "H-20" if he takes another hit, it would update two times to get to H-40 and not take the damage it has already decreased + 20.
If you know a way to do this smooth transition inside a function please explain it to me, that would be really nice.
Thank you, Eresea
Use two functions perhaps?
One function does the actual updation of health from current health to target health. This is called in every tick. Use a FInterpTo node or update the health value manually based on Delta Seconds. Lets call it UpdateHealth.
The second function is called with a target health as param, which sets the value of TargetHealth. This is called only once. Lets call it SetTargetHealth.
so say, your characters current health is 100. But he takes a damage of 40. You will call the second function SetTargetHealth(60). And thats it. The actual interpolation will be done by the UpdateHealth function over time.
answered Aug 08 '14 at 02:59 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here