# Lerp waypoint path easing

Hey folks, I’m making a path animation tool using waypoints and I could use some help with the math. It’s set up like this: you feed it a fixed amount of time for the animation to play and finish, for example 3 seconds. The script iterates through the waypoints (a vector3 array) and Lerps a transform between the current and next waypoint. The Lerp speed is calculated by dividing the total animation time with the distance between the designated waypoints, resulting in a constant speed over the entire array.

Now I want to use an AnimationCurve or any other slightly customizable method to easy the ENTIRE animation in and out. The problem is that an AnimationCurve works very well with a single Lerp as time value, but is harder to stretch over all these tiny Lerps which use a constant, calculated speed.
Here’s a snippet to give you an idea:

``````currentSpeed = animationTotalTimeInSeconds / Vector3.Distance(path[currentPoint], path[nextPoint]);
waypointTime += Time.deltaTime * currentSpeed;

targetTransform.position = Vector3.Lerp(path[currentPoint], path[nextPoint], waypointTime);
``````

Just multiplying the currentSpeed with an AnimationCurve.evaluate alters the SPEED, but I still want the total animation length to be the same, which is TIME.

Any ideas on how to fix this or faced a similar problem?

Thanks.

Well Lerp is more of a position based timeline, so if you are trying to have a constant value, you may want to make your character look at the next point and move by a fixed amount of time using something like this.

``````transform.LookAt(path[nextPoint]);
transform.Translate(Vector3.forward * animationTime * Time.deltaTime);
``````

I am having a little bit of trouble understanding your entire question, so if I didn’t answer correctly, you can give me a bit more insight on your end achievement.

Hope this helps!
_