ok, I have looked through about 30 examples, spent the night going back and forth over the documentation and searching the forums and I feel safe to say the time has come for me to simply as the question.
How the Mathf.Lerp function actually works is just beyond me at the moment. What I am trying to accomplish is relatively simple. I have a current speed, a top speed and an acceleration rate. Lets say my object is not moving, so its current speed is 0, its top speed could be, lets say 60. The acceleration rate is the amount of time in second I would like it to take to go from 0 to topspeed.
The only way that comes to mind is by having a variable keep track of the time that I start the acceleration, and using that to figure out what time it should reach top speed, like this:
function Accelerate(currSpeed:float, startTime:float){
var targetTime = startTime + accelRate;
var remainingTime = targetTime - Time.time;
var accelPrecent = (accelRate - remainingTime) / accelRate;
var newSpeed:float = Mathf.Lerp(currSpeed, topSpeed, accelPrecent);
return newSpeed;
}
but that just seems like its overly complicated. And not only that but releasing the accelerate button would force the accelerate timer to then reset and take the full accelerate time to then go from current speed to topspeed, rather than from 0 to topspeed. And frankly doesn’t work right anyway. It actually reaches its top speed in about half as much time as the accel rate should let it.
Now I know I should be able to use variables such as Time.deltaTime to my advantage here, but I just cant grasp how I could do so, and when I have gotten lerps to appear to work in the past using Time.deltaTime in calculating the t parameter of lerp like this, it never seems to actually reach the destination value.
I would greatly appreciate if someone could explain this chronological nightmare to me so I can figure out what I’m doing wrong and be able to actually use this again in the future.
Thanks,
Alima