Skip to main content
Participant
June 26, 2023
Question

How do I link an animation to the duration of a layer?

  • June 26, 2023
  • 1 reply
  • 192 views

Hi there,

I'm building a template for a client to embed social media videos into a main video. I want them to be able to drop the videos into precompostions and simply change the length of that composition. Then in the main composition I want the videos to scroll in and out of frame at the beginning and end of the composition. How can I "link" the position animation to the variable end of the precompositon, so they don't have to move the keyframes? So no matter how long the precomp ist, once it ends, the video will slide up?

(I hope I could explain this okay, English is not my first language)

Thank you for your help!

Lara

This topic has been closed for replies.

1 reply

Community Expert
June 26, 2023

You have to set up an animation that uses the layer in-point and out-point as drivers for an interpolation method. Something like this:

 

y = thisComp.height/2;
Xstrt = - sourceRectAtTime().width/2;
Xmid = thisComp.width/2;
Xend = thisComp.width - Xstrt;
t = time - inPoint;
dur = .5;
if (t < dur){
	x = easeIn(t, 0, dur, Xstrt, Xmid);
}
else{
	x = easeOut(t, outPoint - dur, outPoint, Xmid, Xend);
}
[x, y]

 

That expression will give you a half-second slide in and slide out based on the layer in and put points. It will work with shape, text, or footage layers and comps as long as you don't scale the layers. If you need to scale the layers, you will need to throw in a scale multiplier for the start and end positions. The anchor point must be at the default middle of the layer position, and a text layer needs to be center justified unless you throw in a sourceRectAtTime.left value.