0 votes

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)
in Engine by (153 points)

2 Answers

+1 vote
Best answer

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.

https://docs.godotengine.org/en/3.2/classes/class_@gdscript.html?highlight=lerp#class-gdscript-method-range-lerp

by (10,928 points)
selected by

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

0 votes

enter image description here

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

https://docs.godotengine.org/en/3.2/classes/class_gradient.html

by (1,667 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.