Hi,
I would like to draw a curve (with handles on key points, etc) in a 2d editor window, and then use this as a look-up table, so if I provide x, I get y. I’ve seen the animation curves, and the curve creation bit looks nice but I am unsure how to apply it. Are animation curves the way to do this, or is there some other, more simple curve type I can use in a script? I just want to graphically draw a curve and access the x and y, it has nothing to do with animation.
The animation curves in Unity are probably what you are after. Typically once you set the curve in the editor in code you can query it with:
animationCurve.Evaluate(yourValue);
Typically you have your curve in a 0 to 1 range so you pass in a percentage. So if you want to get points on an entire curve you do summate like
for(int i = 0; i < 100; i++)
x = animationCurve.Evaluate(i / (float)100);
In this case 100 means you sample 100 points on this curve and should give a decent shape
1 Like