Hello, I am trying to figure out how I am able to get the reverse value of a Lerp. To clarify I want to get the alpha value of a Lerp by using the returned value of a regular Lerp.
Ways I have tried using:
-
Instead of using the regular Lerp function I instead tried substituting the value with the alpha which would normally work with numbers but wouldn’t work with other types of values such as Vectors.
-
I also tried changing the start and goals into percentages but it will not work with other types of values as well.
-
Lastly, I tried using the regular Lerp function to then get the value and return it with the Alpha value but it wouldn’t be useful because you already know the alpha. Which I am trying to get without any pre Lerping to already have the alpha value.
local function Lerp(a,b,i)
return a + (b - a) * i
end
local function ReverseLerp(a,b,v)
return = a + (b - a) / v
end
local Start = Vector2.new(0,0)
local End = Vector2.new(1,1)
local Alpha = .5
local Value = Vector2.new(.5,.5)
Lerp(Start,End,.5) -- prints(Vector2.new(.5,.5) )
ReverseLerp(Start,End,Value) -- prints(Vector2.new(2,2) ) with multiplying it will print Vector.new(.5,.5)
-- ReverseLerp should print .5 because it is in the middle
– How would I be able to get the alpha through the value?