Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Move object from one end of a SourceRectAtTime rectangle to the other over time

Tagged: 

  • Move object from one end of a SourceRectAtTime rectangle to the other over time

    Posted by Kieran Lefort on February 9, 2021 at 11:36 am

    Tagged as “Basic”, but might not be.

    I have a rectangle, the width of which is controlled by the SourceRectAtTime() of a text layer.

    I also have a circle. At 0 frames, the circle needs to be at the left edge of the rectangle. at 25 frames, it needs to be at the right edge.

    Regular keyframes obviously aren’t going to cut it because the rectangle can be any width.

    I haven’t had to do do any expressions for about a year, so my brain has shut down. ?

    Trent Armstrong replied 5 years, 3 months ago 2 Members · 7 Replies
  • 7 Replies
  • Trent Armstrong

    February 9, 2021 at 1:32 pm

    Kieran! This is awesome! I love dynamic setups like this that can change based on other elements in the comp.

    You will probably want to use linear() or ease() to accomplish this. It would look something like this:

    L = thisComp.layer(“Shape Layer 1”); //Pickwhip the layer you are referencing

    w = L.sourceRectAtTime().width * .5;

    startPos = L.toComp(L.anchorPoint) – [w, 0];

    endPos = L.toComp(L.anchorPoint) + [w, 0]

    endFrame = framesToTime(25);

    ease(time, 0, endFrame, startPos, endPos) // For a more harsh animation you could use linear() instead

  • Kieran Lefort

    February 9, 2021 at 1:40 pm

    Haha! Hi, Trent. I’m glad you like it. Most of the stuff I’ve done in expressions has been for dynamic setups like text that can be of any length etc.
    The following on the circle’s position almost works:-

    rectLeft = thisComp.layer(“rectangle”).sourceRectAtTime().left;

    rectRight = thisComp.layer(“rectangle”).sourceRectAtTime().left + width;

    easeOut(time,0,1,[rectLeft],[rectRight])

    I’m going to try yours now.

    EDIT: Forgot to mention that I’ve already separated the X and Y dimensions. I often find Position easier to work with like that if I only need to affect one dimension.

  • Trent Armstrong

    February 9, 2021 at 1:44 pm

    Kieran,

    You can also do a thing where you read the time of keyframes into the ease() expression start and end range. That allows you to change the length of the move by adjusting the position and distance between those keyframes.

  • Kieran Lefort

    February 9, 2021 at 1:51 pm

    startPos = L.toComp(L.anchorPoint) – [w,0]; is giving me an “Invalid or unexpected token” error.

    Currently investigating.

  • Trent Armstrong

    February 9, 2021 at 2:00 pm

    There is something wrong with the formatting that is happening with the blog post. It’s a bit of a hassle, but try typing it instead of copy/paste. I had trouble with the quotes on the first line and then some character on the startPos line. Not sure what that’s about. 😐

  • Kieran Lefort

    February 9, 2021 at 2:10 pm

    I’ve had to make a tiny tweak to startPos to make it fit around my own terrible scripting, but that’s done the trick. Thanks so much!

  • Trent Armstrong

    February 9, 2021 at 3:04 pm

    You bet! Have fun with those expressions!

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy