• Lerping A HUD Health Bar?
    3 replies, posted
Hey everyone. After having worked with Glua for quite a while now, I've only recently gone in to making proper HUDs. Therefore, I was wondering how one would go about lerping the health bar? - as seen on many HUDs. I've tried a bunch of different things, yet nothing seems to do the job. Google doesn't help much either; only showing me lerps from one value to another. A health value would be dynamic all the time. Any help is much appreciated :D -FP
what do you mean by "A health value would be dynamic all the time."
[QUOTE=bloodmasked;52152095]what do you mean by "A health value would be dynamic all the time."[/QUOTE] Well, most of the examples that Google provides lerp say 0 to 100. I'd need to lerp X to X. My problem is basically how I'd properly save the old health value and the new one. If I do this in HUDPaint, then it will override the old health value before the lerp has completed. [editline]26th April 2017[/editline] [QUOTE=Moat;52152104]Simply set the "to" argument for the lerp to the player's health divided by their max health. It'll return a number between 0 and 1, which you can use to multiply the max width of your health bars by. Here's an example I posted a while ago: [lua] Fantastic! Thanks a lot Moat! local color_blue = Color(0, 0, 100) local color_blue_light = Color(0, 0, 255) local healthbar_max_width = 200 local healthbar_cur_width = 0 hook.Add("HUDPaint", "DrawHealthBarTopLeftCorner", function() local localplayer = LocalPlayer() -- Lerps the current width to a number between 0 and 1 (health divided by max health) healthbar_cur_width = Lerp(FrameTime() * 5, healthbar_cur_width, localplayer:Health() / localplayer:GetMaxHealth()) draw.RoundedBox(0, 10, 10, healthbar_max_width, 30, color_blue) --background for health bar -- main health bar, width = max width multiplied by the lerp number (between 0 and 1) draw.RoundedBox(0, 10, 10, healthbar_max_width * healthbar_cur_width, 30, color_blue_light) end) [/lua][/QUOTE]
Sorry, you need to Log In to post a reply to this thread.