How would I modulate using a percentage?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Dragon20C

I have a sprite that is the hp of my player, I also have a percentage that starts at 100 ( of course), What I want to happen is at 100% I want it to stay its normal white colour but when it reach a low % like 0 or 50 I want it to be red, and making it even redder the lower the number it is!, so my question is how would I convert the percentage so that it fits the modulate 0 to 1 format?

This is what I have:

health_symbol.set_modulate(Color(0.1,0,0))

and this is my health percentage being calculated (just assume it has a variable already attached to it):

 (current_health / player_health) * 100)
:bust_in_silhouette: Reply From: jgodfrey

I think you’re looking for range_lerp(), which will let you map a value in one range to an equivalent value in a different range.

That sounds exactly what I needed thank you, appreciate it!

Dragon20C | 2020-11-04 17:33

:bust_in_silhouette: Reply From: rakkarage

enter image description here

you can define a custom gradient with red gradient at bottom and white at top