Healthbar effect.


Im currently busy with a PUBG HUD, but I need a effect added to it.
I am looking for the following (bleep) effect:

Whenever a player is under a certain ammount of health the healthbar will bleep.

1 Like

You mean a fade in/out? Like a slow pulse? I don’t think it’s super complicated, probably just assigning your RGB values to some changing variables, but I don’t know how to do it exactly.

Change it alpha value inside SetDrawColor with math.cos(RealTime()*frequency)*waveLenght

Thanks, but i only need a lil help out here.
Already got my lerp in there aswell. How would i apply that to it?

 	sHP = Lerp(10 * FrameTime(), sHP, LocalPlayer():Health()) 

 	if (health <= 25) then
		draw.RoundedBox( 0, 715, ScrH() - 100, 4.6 * sHP, 50, Color( 255,255,255, 255 )) 

Check the color parameter in draw.RoundedBox

You mean that I need to replace it with the Math? Or?


local alpha = math.cos(RealTime()*frequency)*waveLength -- replace frequency and wavelength with some numbers idk
draw.RoundedBox( 0, 715, ScrH() - 100, 4.6 * sHP, 50, Color( 255,255,255, alpha )) 

EDIT: this is just based on what gonzalolog said. I don’t know if it works but I literally just copy pasted his answer

math.cos returns a value between -1 and 1. I don’t know what effect giving an alpha value (or any RGB value) a value under 0 does.


Values under 0 will be clamped by Color structure.

If you use cos or sin there half of lenght it will pulse others not.

If you want to pulse with pause try:

math.abs( math.cos( RealTime()*frequency )*waveLenght ) )

it will be positive everytime (0 is lowest)

Also try not completed fade:

local alpha = 127 + math.cos( RealTime()*frequency )*waveLenght 

it will pulse from 127+waveLength to 127-waveLenght
This is useful when you need a fade but save visibility.

The first code with

math.abs almost same as:

local alpha = 127 + math.cos( RealTime()*frequency )*127

The fade will be from 127+127 (254 in total) to 127-127 (0 in total)

**Examples: **

Fades of (0,0,0) on (255,255,255)

Numbers of alpha was rounded
1. math.cos(CurTime()*2)*255
2. math.abs(math.cos(CurTime()*2)*255)
3. 127+math.cos(CurTime()*2)*50
4. math.abs(math.sin(CurTime()*2)*255)

Can we get more shit like this on the wiki, please?

You learn this ‘shit’ in 6th grade. Its called trigonometry + basic math/logic.

Use HSV color format for this.
local rate, amp = 2, 0.4
local color = HSVToColor( 0, 1, 1 - amp / 2 + math.sin( CurTime() * rate ) * amp / 2 )
rate - rate of flickering
amp [0…1] - amplitude (intensity) of flickering


That’s a really immature way to respond, and it kinda hurts. I’m an aspiring games developer, and I’m sorry I’m not perfect and don’t fully grasp every piece of code or math logic right away, but it’s been 3-4 years since I’ve worked with any kind of trigonometry, and it didn’t stick well to begin with. I’m taking college classes right now so I’m actively trying to improve myself, but your comment doesn’t help any.

Additionally, It’s not hard to add some helper information into the wiki, and it helps out more people than the no one it negatively effects.

Maybe think a bit more about the impact your words have before you use them.

I thought i should mention the wiki does already have a page on this.


math.cos and

math.tan aren’t hard to understand, at least for what you want to do with them. I don’t even know them properly, but all I know is they’re great for smooth waves. They usually output a number between -1 and 1, so FaceSparTV’s code increases this range to 0 and 255 (to fit the

Color range) by simple multiplication and addition. You could also use

math.abs * 255, but his method is better.

It depends whether you want the alpha to fade from 0 to 255 or the color to fade from 0 to 255. I wouldn’t recommend using

HSVToColor unless you want to make rainbows, because it has a lot more lines of code than you actually need. If you want a simple grayscale fade, then just set the R, G and B to the same thing.