2

I'm new to using expressions in after effects and I've also hardly touched Java before. However using some online tutorials and common sense, I managed to create a lower thirds title graphic yesterday, the java is used to change it's position based on how much text is written inside. The title graphic bleeds off to the left of the screen, so when text is written on it, it moves left or right to match the length of text. I've included the code below.

s =thisComp.layer("Header title");
x = s.sourceRectAtTime(time-s.inPoint,true).width;

subl =thisComp.layer("Sub title");
subt = subl.sourceRectAtTime(time-subl.inPoint,true).width;

text = Math.max(subt, x) -100;

max = 659.4;
m = Math.min(max, text);

[m, 871]

So with a little bit of text: graphic position with less text

With more text: graphic position with more text

Where I'm struggling is I want to make this into an animated motion graphic, where the graphic just slides in and out at the right time. However, if there's less text, it's position is further out the frame and it takes longer to slide in - which means that it's out of sync with other parts of the animation. I'm not worried about consistent speed, I just want it to appear in at the same time as it has to match other animations. The only way I can see this happening accurately is by further encoding, where it gets a little beyond me!

I tried animating using if expressions dependant on the time function, but this didn't create a transition, the graphic jumped instantly from point to point. I can't find anything on creating keyframes in java either so not sure the best way to do this.

Really appreciate any help to put me on the right track.

1 Answer 1

1

There are some built-in functions just for this purpose. You'll find them in the interpolation folder in the expression drop-down. The simplest is the linear() function:

linear(t, value1, value2)

This function interpolates in a linear fashion between value1 and value2 based on the value of t, where 0 ≤ t ≤ 1. So if t=0 the function returns value1 and if t=1 it returns value2. It can also take five parameters, in the form

linear(t, tMin, tMax, value1, value2)

in this form, instead of using the range 0-1 for t it uses the range tMin to tMax.

Along with linear() there are also ease(), easeIn() and easeOut(). These interpolate with easing - meaning the animation slows down at the beginning or end, or both.

So in your example you could add this before the last line:

startTime = inPoint; //if you want the animation to start at the start of the layer
m = ease(time-startTime, 0, animationLength, 0, m)

this will smoothly animate from the layer's in-point for animationLength seconds to the calculated position.

Oh, BTW it's Javascript not Java. They are completely different languages. As they say, Java and Javascript are similar in the same way that "car" and "carpet" are similar.

2
  • I guess everyone's been using that expression for years... but I think that's AWESOME! I think I've just fallen in love with AE expressions :) Thanks a bunch, I haven't tried my original example yet but I just ran a quick test to make sure I understand how it works and I think I know how to work my motion graphic now! thanks again!
    – AutoBaker
    Commented May 16, 2018 at 13:36
  • Expressions are the most powerful part of After Effects IMHO
    – stib
    Commented May 16, 2018 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.