Lerping between Multiple Points of Color3 Values?

Hi,

So Im wondering on how to do this with `Color3` values, where I you Interpolate between Points, I already know How to make a Basic Color Interpolation, like for Example a Health bar, where if the Player reaches a Certain point in their Health, The Color would interpolate it to where its in between Green and Red, like so:

``````local lerpC3 = function(a, b, t) -- Tweening (or Interpolating) a Color3
return Color3.new(a.R * (b.R - a.R) * t, a.G * (b.G - a.G) * t, a.B * (b.B - a.B) * t)
end

local empty = Color3.new(1,0,0) -- when the Bar is about Empty
local full  = Color3.new(0,1,0) -- when the Bar is Full

Humanoid.HealthChanged:Connect(function(hp) -- HealthChanged
Frame.BackgroundColor3 = lerpC3(empty, full, hp/Humanoid.MaxHealth) -- Interpolated Color
Frame.Size = UDim2.fromScale(hp/Humanoid.MaxHealth, 1) -- Size
end)
``````

How would I Lerp between More than two Points? Like for Example: If a Player had Full `Health`, It would be green, but if they gain an Ability for more `Health` above the `MaxHealth`, it would transition to a Yellow, and if it were Lower than the `MaxHealth`, it would transition to a Red.

Would I need to check if the Value is above a Certain amount? or can I do this with by a method of Lerping?

2 Likes

You probably would need to, I would create an `if` statement to check if itâ€™s above something, if it isnâ€™t then show red and if it is then show yellow

(Also why do you have strange caps? Like:

Iâ€™m just curious)

1 Like

Maybe, but I kind of want to get more info than just a â€śprobablyâ€ť.

You would just need to compare Health to MaxHealth - if Health is greater than MaxHealth, lerp from `full` to the yellow Color3; if Health is less than MaxHealth, lerp from `full` to `empty`. Iâ€™m not sure if thereâ€™s a way to strictly do this with only lerping, but you can certainly do this using if statements.

By the way, you can use Color3:Lerp() instead of writing your own lerp function.

Until I test this itâ€™ll remain a â€śprobablyâ€ť
Sorry

Im Aware, but Id rather make my own.