FORUMS: list search recent posts

# Anyone know how to hold values from previous keyframes for limited amounts of time?

FAQ   •   VIEW ALL
 Anyone know how to hold values from previous keyframes for limited amounts of time? on Jul 15, 2016 at 3:41:16 pm

I'm trying to accomplish something very specific, and cannot find this info anywhere.
I have position keyframe data, and I want to add an expression that causes each keyframe to hold it's values until a set number of keyframes before the next keyframe.
So let's say I have a solid at [0,0] at 0:00, at [0,100] at 10:00 and [0,200] at 20:00
I want each keyframe to hold until 12 frames before the next, so the solid stays at [0,0] until 09:12 and then interpolates to [0,100].
It holds [0,100] from 10:00 to 19:12 and then interpolates over the next 12 frames to [0,200]

Basically, I'm trying to give every single keyframe a lead in of 12 frames (or some other value) without having to copy and paste every keyframe that came before it and dragging it to the correct spot 12 frames before the next.

Is this possible?
Thanks everybody!

 Re: Anyone know how to hold values from previous keyframes for limited amounts of time?on Jul 15, 2016 at 4:12:37 pmLast Edited By Kalle Kannisto on Jul 15, 2016 at 4:13:54 pm

I'm sure you could write an expression for it, but you can also copy all the keyframes, move 12 frames backwards and paste with the same result.

 Re: Anyone know how to hold values from previous keyframes for limited amounts of time?on Jul 15, 2016 at 4:17:38 pm

Hi Kalle!

I thought of that, but unfortunately it doesn't work. In my example, all the keyframes are even spaced, so I could just copy and paste 12 frames over, but in my project, the spacing varies and so when I paste and slide them over some are more than 12 frames or less than 12 frames away.
I need to write an expression that takes into account the values of the previous keyframes, and the number of frames until the next keyframe, so that no matter what variation I have between keyframes, the interpolation always starts 12 frames before the next.

 Re: Anyone know how to hold values from previous keyframes for limited amounts of time?on Jul 15, 2016 at 4:35:09 pm

I don't understand this part: "so when I paste and slide them over some are more than 12 frames or less than 12 frames away". How does that happen? If you move 12 frames back and paste, all the pasted keyframes should be offset -12 frames from the originals. I don't see how anything else can happen. Do you mean there are places where there are less than 12 frames between keyframes, which would certainly be a problem?

 Re: Anyone know how to hold values from previous keyframes for limited amounts of time?on Jul 15, 2016 at 4:43:05 pm

Something like this maybe:

``` runFrames = 12; n = 0; if (numKeys > 0){ n = nearestKey(time).index; if (key(n).time > time){ n--; } } t = time; if (n > 0 && n < numKeys){ tf = framesToTime(runFrames); t1 = key(n).time; t2 = key(n+1).time; if ((t2 - t1) > tf){ if (time < (t2 - tf)){ t = t1; }else{ t = linear(time,t2 - tf, t2,t1,t2); } } } valueAtTime(t); ```

Dan

 Re: Anyone know how to hold values from previous keyframes for limited amounts of time?on Jul 15, 2016 at 4:52:08 pm

This is great! It works even better than the other code posted. For some reason puppet pins respond poorly to Kalle's code, and it needs reformatting from one property to another, but as far as I can tell this works universally. Thank you so much!

 Re: Anyone know how to hold values from previous keyframes for limited amounts of time?on Jul 15, 2016 at 4:27:16 pm

If you use hold keyframes, here's an expression that will do what you asked:

```keydistance = 12; nextkey = nearestKey(time); nextkeytime =nextkey.time-time; if (nextkeytime<keydistance*thisComp.frameDuration) {linear(nextkeytime,0,keydistance*thisComp.frameDuration,transform.position.valueAtTime(nextkey.time),value)} else {value} ```