Say I have two values assigned to two respective keys, one “high” and one “low”. Now, I have a new key somewhere in between those two extremes. How would I retrieve a value based on how close/far the new key is to either of the extremes? For example, let’s say I have 1 assigned to 10 and 2 assigned to 20. How could I make 1.5 return 15?
function assignNumber(n)
return n * 10
end
print(assignNumber(1)) -- -> 10
print(assignNumber(1.5)) -- -> 15
print(assignNumber(1.8)) -- -> 18
print(assignNumber(2)) -- -> 20
Is this what you meant?
What you’re describing is linear interpolation.
local function Lerp(Start, End, Alpha)
return Start + ((End - Start) * Alpha)
end
print(Lerp(10, 20, 0.5)) --15
Unlike the previous solution this is compatible with any set of values.
2 Likes
No, that was just an example. Like Forummer said, I want something compatible with any number. Thank you, though!
1 Like
This is what I wanted, thanks 