- Home /
Add Resistance to Lerp Value
Hello,
I have a lerp value between 0 and 10. The value it spits out go into a variable called Power. Right now, the lerp is linear. In other words, if the lerp spits out 4, then Power will be 4.
Is there a way to make it a ease in a bottle neck effect?
Thats just an example of how the lerp bottleneck will work. It's so it feels like theres resistance, or tension within the value.
Imagine pulling something elastic, to begin with its fairly easy to pull, and the power increases easily. But after a certain point the power begins to resist, hence a 'bottle neck' effect (kinda).
In my app, the user pulls back on a graphical 'elastic band' type object. So I want it that when the user reaches near the '10' point within the range, the lerp pullback decreases.
I hope I've worded this correctly. Thanks.
---- Update ----
I've done this:
var resistance = ( ( (power / power) * 20 ) / power * 400) / 20;
20 being the max clamp of power. This kind of works, although its the opposite way around. To being with, the values are very close to one another. The closer power comes to 20, the more spread out the values are - so its the opposite way around.
Is there a way I can just use a formula from a curve, and use that?
I tried using the fomulas from this site: http://www.gizma.com/easing/
But the params it requires include time, and duration - something I'm not using, so how would this work?
Answer by robertbu · Feb 11, 2014 at 04:14 PM
With easing functions, it might be easier to construct them so that take inputs in the range of 0.0 to 1.0, and output values in the range of 0.0 to 1.0. If you take a look at the equations on the site you have a link to, you will see that they start each one with:
t /= d;
This produces a fraction in the range of 0.0 to 1.0.
So taking a look at your curve above, it looks like the Sin(x) from 0.0 to PI/2. So a function might be:
var Map(in : float) : float {
return Mathf.Sin(in * Mathf.PI / 2.0);
}
So now your power value goes from 0 to 10. Call 10 'maxPower'. You could get your power level by:
curvedPower = Map(powerIn/maxPower) * maxPower;
Another equation that has a similar curve to your drawing above is x^0.5. So the map would be:
var Map(in : float) : float {
return Mathf.Pow(in, 0.5);
}
If the ease function is suppose to take values between 0 and 1, the 'curvedPower' gives out a whole number.
Eg:
powerIn = 5, maxPower = 10
curvedPower = (5 / 10) * 10 = 5.
Surely I don't need to multiply it by maxPower at the end?
??? the '* 10' is multiplying it by maxPower. A $$anonymous$$ap() function like I describe should always return values in the 0.0 to 1.0 range. Given your curve, for the whole calculation, you want 0 to return a power of 0.0 and a value of 10.0 to return a value 10.0. Since the $$anonymous$$ap() function only returns a fraction, you need to multiple by maxPower to get the values in the range you want.
Note than an input of 5 / 10 (0.5) is not going to produce an output of 0.5 from the $$anonymous$$ap() function. For Sin() it will 0.71, so the curvedPower = 0.71 * 10 = 7.1. For X^0.5, the output for 0.5 is 0.84 so the output will be 8.4.
Answer by BlueRaja_2014 · Feb 11, 2014 at 04:32 PM
You could try using a Sigmoid Curve like the logistic function
position = 10 / (1 + Math.Exp(-t);