StingRay21
StingRay21

Reputation: 362

Linear Interpolation More Linearly

I'm curious if there's a way to make this function:

float linearInterpolation(float startPoint, float endPoint, float time)
{
    return startPoint + ((endPoint - startPoint) * time);
}

More linear, as right now when the start point nears its endpoint it goes slower, i just want it to go the same speed all the way through no slowing down/speeding up. If i need to implement another variable or something that can be done. Another function that would take the same variables and output the next value would also be acceptable.

Upvotes: 1

Views: 593

Answers (1)

radcore
radcore

Reputation: 339

That looks like a correct implementation of lerp to me. Without seeing the code that you are calling it with, I'm going to guess that the reason it is slowing down is that you are calling it with a different startPoint (calling with the previous result of the call to linearInterpolation would cause this) each time (frame?) which would cause it to slow down as the distance to interpolate is reduced each time it is called.

Make sure the startPoint and endPoint variables are the same for each call over the life of the interpolation and only the time variable is increasing.

Upvotes: 1

Related Questions