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?