I tried to look for an answer for this problem but I guess nobody has needed something like this or it’s something super simple that I just can’t get my head around. So:
I have a value that changes from 45 to 20.
I’d need a value that goes from 0 to 1 in same time as 45 goes to 20. I know that 45 – 20 = 25 and that would be my 100% and hence the number 1.
I’d implement this in Lerp value like this:
public float minHeight = 10.0f;
public float maxHeight = 30.0f;
public float convertedValue;
convertedValue = ??? (Something like 45 – 20 = 25 = 100%) * 0.01;
newValue = Mathf.Lerp(minHeight, maxHeight, convertedValue);
Hopefully someone can help me. Im fairly new to coding and I was just wondering if this is possible. Thanks for your time!
I believe the calculation matching your explanation would be
i.e.
newValue = 0@minHeight, and 1 @maxHeightEdit
I’ve never seen Lerp before, but apparantly it is simple linear interpolation.
However, from MSDN
Lerp is defined as
i.e. in your example
convertedValueshould be the fraction, and the answer is the interpolated result, meaning that your question / my (and Esailja’s) interpretation thereof is inverted 🙂i.e.
whereas
🙂