- Home /
Create a linear animation curve with javascript
Answer by IgnoranceIsBliss · Nov 14, 2012 at 04:17 AM
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.
I'm using animation curves to simulate a car's motor behavior and not for a animation. It is faster for me to set the values of my curves by code than with the animation curve editor, beside i may need sometimes to be able to build a curve from values calculated at runtime. I'll look into $$anonymous$$athf library.
Thank you your answer
Your answer
Follow this Question
Related Questions
Tranform Animation Curve ruins Gravity 1 Answer
Animation Events and Mecanim 2 Answers
Animator Jerky Animations 0 Answers
key count: 1 on curve 'curvename' error 1 Answer
Evaluating Animation Curves in Full 0 Answers