- Home /
Question by
Matt-Ostgard · May 13, 2014 at 11:57 PM ·
c#animationcurvekeyframetangent
How do I scale an animation curve by time and value while retaining my tangent values?
I have an artist defined animationCurve that is supposed to describe how an object comes to a stop. The first key frame is at 0, 1 and the last is at 1, 0. I need to scale that curve's time by stopTime and its value by maxSpeed.
Here is a test I did:
///////////////////////////
using UnityEngine;
using System.Collections;
public class AnimCurveScaleTest : MonoBehaviour {
public AnimationCurve artistCurve;
public AnimationCurve scaledCurve;
Keyframe[] tempKeys;
float speed = 1000f;
float stopTime = 0.5f;
// Use this for initialization
void Start () {
tempKeys = new Keyframe[artistCurve.length];
for ( int i = 0; i < artistCurve.length; i++ ) {
tempKeys[i] = new Keyframe(
artistCurve[i].time * stopTime,
artistCurve[i].value * speed,
artistCurve[i].inTangent,
artistCurve[i].outTangent
);
}
scaledCurve = new AnimationCurve( tempKeys );
}
}
//////////////////////////////
And this is the result:
Comment
Why scale the curve at all? Why not normalize your input using stopTime, and scale your output by maxSpeed?
Yeah thats what I'm doing currently. I'm also trying to do other things with curves, though, like combining them. I'm trying to keep it as optimized as I can during the event. This is the simplest example with the same problem, though.
If no one knows I will stick to just if statements and what not, but I'm hoping someone has an answer.