Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AnimationCurve.Evaluate - Get time by value

Tags:

unity3d

curve

Is there a build-in way how to get a time by value from Animation curve in Unity3d? (The opposite way of Evaluate)

I need to achieve this (instead of getting value from time):

float time = AnimationCurve.Evaluate(float value);

Generically speaking getting X value from Y value.

like image 778
David Horák Avatar asked Aug 27 '14 12:08

David Horák


1 Answers

I know this is 3 years old, but I found via a Google search, and in case someone else lands here:

I simply create an inverse curve, which allows me to look up by time.

public AnimationCurve speedCurve;

private AnimationCurve inverseSpeedCurve;

private void Start()
{
    //create inverse speedcurve
    inverseSpeedCurve = new AnimationCurve();
    for (int i = 0; i < speedCurve.length; i++)
    {
        Keyframe inverseKey = new Keyframe(speedCurve.keys[i].value, speedCurve.keys[i].time);
        inverseSpeedCurve.AddKey(inverseKey);
    }
}
like image 158
user2330450 Avatar answered Oct 04 '22 00:10

user2330450