Editing animation curves in a script

Hey there!

I’ve been trying to set the keyframes of an animation curve in script, but for some reason it isn’t using the values I assign to it. See the below picture.

As you can see in the code, the value of the last key should be 0.5, and the value of the fourth should be 1. But those two are inverted. Anyone know how I can fix this?

That curve looks correct to me, assuming spline.SplineLength has a value of about 21?

keyFrames[3].time = 1.5 * spline.SplineLength;
keyFrames[4].time = spline.SplineLength;

So the value on the right hand end of the curve is keyFrames[3], not keyFrames[4]…

If for some you wanna edit the curves visually, not in script, check out Runtime Curve Editor: