- Home /
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.
I just realized the animationTotalTimeInSeconds isn't even time in seconds but also some kind of speed. The case in which I was using it just happened to be around the same amount of time as I was putting in it.
Answer by Bubinga_Studios · Aug 01, 2018 at 03:36 PM
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!
Hey thanks for your answer. I'm avoiding using Translate or $$anonymous$$oveTowards or any other movement method because I use Lerp info for other stuff as well.
$$anonymous$$y question has gotten a bit convoluted but basically what I'm asking is how would you smooth/ease a "speed" variable, but keep the entire thing a constant "time". It gets complex because it's multiple tiny Lerps that make up a single animation.