ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Change time between keyframes

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Kevin Snyder
Change time between keyframes
on May 22, 2017 at 7:04:23 pm

Is it possible to change the time between keyframes using expressions? For example, I want to set two keyframes to animate a square's position over 1 second. Then, I would like to apply an expression that would allow me to play the keyframed animation over a specified amount of time, 3 seconds for example.


Return to posts index

Dan Ebberts
Re: Change time between keyframes
on May 22, 2017 at 7:22:02 pm

You can simulate moving a keyframe using valueAtTime(). How would you specify the new timing?

Dan



Return to posts index

Kevin Snyder
Re: Change time between keyframes
on May 22, 2017 at 7:58:19 pm

That's a great question...Ideally, I would specify how long the keyframes should play in seconds using a slider...would that be possible?


Return to posts index


Dan Ebberts
Re: Change time between keyframes
on May 22, 2017 at 8:09:56 pm

Something like this maybe:


dur = effect("Slider Control")("Slider");
if (time < key(1).time){
value;
}else if (time < (key(1).time + dur)){
t = time - key(1).time;
d = key(2).time - key(1).time;
valueAtTime(key(1).time + d*t/dur);
}else{
t = time - (key(1).time + dur);
valueAtTime(key(2).time + t);
}



Dan



Return to posts index

Kevin Snyder
Re: Change time between keyframes
on May 22, 2017 at 9:31:25 pm

That works great for two keyframes. Thank you. Is there a flexible way to make it work for multiple keyframes where the number of keyframes can change? Many thanks.


Return to posts index

Christian Geijer
Re: Change time between keyframes
on Oct 4, 2018 at 12:22:08 pm

Hi,

A large and late bump, but I thought to reply here instead of starting a new thread.

I have a template where I've placed two sliders with two keyframes each on a control null.
These two sliders are the "masters" for different animations within the comp. One for "build in" and one for "build out":



I've written an expression that I can apply to every layer and property I want to control with a linear-function mapped to the "masters".

It looks like this:

animIn = thisComp.layer("Control").effect("Anim in")("Slider");
animOut = thisComp.layer("Control").effect("Anim out")("Slider");
dur = thisComp.layer("Control").effect("Duration")("Slider");

inBuffer = 0;
outBuffer = 0;

animInTime = animIn.key(2).time - animIn.key(1).time;
animOutTime = animOut.key(2).time - animOut.key(1).time;

animInStart = 0 + inBuffer;
animOutStart = dur - animOutTime - outBuffer;



// calculations for inVal, holdVal, outVal, if needed


holdVal = 100;
inVal = 0;
outVal = inVal;

if(time <= animInStart) {
inVal
} else if(time >= animInStart && time < animInStart + animInTime) {
linear(animIn.valueAtTime(time - animInStart), 0, 100, inVal, holdVal)
} else if(time >= animOutStart) {
linear(animOut.valueAtTime(time - animOutStart), 0, 100, outVal, holdVal)
} else {
holdVal
}


animIn and animOut are the master sliders that go from 0-100 and 100-0 respectively.

The expression uses the animIn-slider to shift from inVal to holdVal and then holds holdVal.
It holds holdVal until it's time to shift, with the animOut-slider, from holdVal to outVal.

I've also built in inBuffer and outBuffer so I can stagger the animation if I want to.

I've tried to integrate your expression in this thread with mine, but I really can't get it to work. Both due to that I'm not an expert on expressions and that I really don't understand how yours works.

In short; I would like to be able to change the duration between the keyframes within animIn and animOut individually with sliders. Is it possible to marry these two expressions together? If yes, how would I go about doing that? Any tips or help you can give me would be appreciated.

Best regards,
/C


Return to posts index


Kevin Snyder
Re: Change time between keyframes
on Oct 4, 2018 at 3:51:39 pm

I would check out this tutorial. I think it will let you get the job done.







Return to posts index

Christian Geijer
Re: Change time between keyframes
on Oct 5, 2018 at 7:11:54 am

Awesome. Thanks for the tip!


Return to posts index

Christian Geijer
Re: Change time between keyframes
on Oct 19, 2018 at 7:22:22 am

I just wanted to return to this in case any stray googler finds this and wonders the same thing.
I think I've solved it. I'm going to expand on this and build some more control over the timings, but the foundation that I've built is this. If anyone have some tips for improvement, I appreciate any pointers. But as for now, I think it works.

Cheers!

iAnimInKeys = thisComp.layer("Control").effect("Anim in")("Slider");
iAnimOutKeys = thisComp.layer("Control").effect("Anim out")("Slider");

tAnimInStart = 1;
tAnimInDuration = 0.5;

tAnimOutDuration = 0.5;
tAnimOutStart = 3;

holdVal = 880;
inVal = 200;
outVal = 540;

if (time &lt; tAnimInStart){
inVal

} else if (time >= tAnimInStart && time &lt; (tAnimInStart + tAnimInDuration)) {
t = time - tAnimInStart;
d = iAnimInKeys.key(2).time - iAnimInKeys.key(1).time;
linear(iAnimInKeys.valueAtTime(iAnimInKeys.key(1).time + d*t/tAnimInDuration), 0, 100, inVal, holdVal)

} else if(time >= (tAnimInStart + tAnimInDuration) && time &lt; tAnimOutStart) {
holdVal

} else if (time >= tAnimOutStart && time &lt; (tAnimOutStart + tAnimOutDuration)) {
t = time - tAnimOutStart;
d = iAnimOutKeys.key(2).time - iAnimOutKeys.key(1).time;
linear(iAnimOutKeys.valueAtTime(iAnimOutKeys.key(1).time + d*t/tAnimOutDuration), 0, 100, outVal, holdVal);

} else {
outVal

}


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]