Create a linear animation curve with javascript

I don’t have the Javascript code (I’m a C# dev) but the process should be relatively simple.

Do you want to actually create an AnimationClip object at runtime?

The easiest way to do this sort of thing in code is by using Mathf.Lerp (Linear Interpolation) and a timer, or using Mathf.SmoothStep which gives you a non-linear movement that speeds up and slows down to create a more organic looking animation path.

Otherwise, you’d need to create a new AnimationClip and create one or more AnimationCurves and add them to the clip with SetCurve.

The curve would have two Keyframes at each extreme end of the animation.

Then assign the Clip to an Animation object, and use Animation.Play. Don’t forget to name your clip so that you can use the name in the call to Play.