Offset last 2 keyframes by X seconds

Scripting for After Effects

Offset last 2 keyframes by X seconds

Postby ivanparas on 07/11/2018, 4:59 pm

I'm making a text template and I need to adjust the last 2 keyframes using an expression so I can vary when the text animates out.

What I have:
A text layer with 4 position keyframes. The first to are the reveal animation, and the last 2 are the hide animation.

What I need:
I need to offset the last 2 keyframes by a number of seconds (or frames) using an expression and a slider.
ivanparas
 
Posts: 255
Joined: 01/21/2009, 10:38 pm
Location: Charleston, SC

Re: Offset last 2 keyframes by X seconds

Postby star+circle on 07/12/2018, 12:41 am

This should do it. The time between keyframes 2 and 3 is stretched to the new length. Slider named "End time offset" is directly on the text layer.

Code: Select all
offset = effect("End time offset")("Slider");
anim_time = time;
if(time>key(2).time) {
   if(time<key(3).time + offset){
   // stretch time
   anim_time = linear (time, key(2).time, key(3).time+offset, key(2).time, key(3).time);
   }
   else {
   // offset time
   anim_time = time - offset;
   }
}
transform.position.valueAtTime(anim_time)
star+circle
 
Posts: 935
Joined: 12/6/2014, 3:07 pm
Location: Finland


Return to After Effects Expressions