- Home /
Tangents ignored while setting keyframes
I am setting an animation curve in the Inspector to exist between the range 0..1. Then on each instance of the prefab using that curve to create a new curve scaled to fit within positionMin & positionMax (values of which are randomised on instantiation).
So I create a new curve, scale the values and copy over the tangents and time. Unfortunately the tangents don't copy over as they are set in the Inspector, but always flat. Even if I set them to wild numbers in this loop (I've tried 0, -10 & 10) all I ever get back is flat tangents. Is this a bug, or am I doing something wrong? Any ideas on ways to do this that works?
(in javascript...)
var keyframes = new Keyframe[anim.length];
for( i=0; i<keyframes.Length; i++ )
{
keyframes[i].value = Mathf.Lerp(positionMin, positionMax, anim[i].value);
keyframes[i].time = anim[i].time;
keyframes[i].inTangent = anim[i].inTangent;
keyframes[i].outTangent = anim[i].outTangent;
}
var newCurve = new AnimationCurve(keyframes);
Answer by Paulius-Liekis · Nov 20, 2010 at 08:42 PM
Ho big is your positionMin, positionMax? I think you need to scale tangents too. See my answer here how tangents are calculated:
http://answers.unity3d.com/questions/24435/how-do-i-set-animation-curve-tangents-from-script
If your value is big and tangent is small then it can look like flat tangets.
On the other hand it might be that tangentMode comes into play here...and I don't know how that works.
Your answer
Follow this Question
Related Questions
What is the length of the Keyframe tangent? 0 Answers
How do I scale an animation curve by time and value while retaining my tangent values? 0 Answers
How can I set the tangents of Keyframes in an AnimationCurve through scripting? 1 Answer
How can I set my Animation Curve's Tangents to Flat in script? 0 Answers
Edit Keyframe of Animation Curve 1 Answer