Limiting a healthbar's scale based on max health

I want to make a healthbar display as full, but in a way so that:

  • Health level 1: Health bar appears full and green at health 10 (base max health level)

  • With each health upgrade, the health bar is full and green at a higher value (20, 30, and so on until 100).

  • The colours (red to green) and scaling follow this same upgrade pattern.

The issue is that keyframes are static. I don’t want to rely on millions of keyframes just to do what many games with upgradeable health bars do…

Do you prefer using Logic Bricks, Logic Nodes, Python Components, or Python?

you only need 100 key frames from 0 to 100 where the first key frame is 0% health and the last key frame is 100% health and the rest is simple math.

example:

maxhealth = 1000
currenthealth = 30

# frame is the animation frame to show.
frame = int((currenthealth / maxhealth) * 100)

The way I usually do this in my jam games is to use Shape Keys. You can make a shape key of the health bar at 0 health, and one at full health. You can also make the color animated by the Object Color property.

Then, you can simply put one keyframe at frame 0, one keyframe at frame 100, and set your current frame to your health value. If set up correctly, it should be nice and smooth.