Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions what drives the expression to loop ?

  • what drives the expression to loop ?

    Posted by Shai Benshoshan on February 20, 2019 at 12:07 pm

    Hi
    Can someone clarify :
    Trying to move the camera from layer1’s position to layer2’s position and then from layer2.position to layer3.position etc…
    I want to understand what drives the expression besides time.
    my regular javaScript doing only the last move (from layer4’s to layer5’s).

    for (i=1; i

    for (i=1; i<index;i++){
    Pos1 = thisComp.layer(i);
    Pos2 = thisComp.layer(i+1);
    P1 = Pos1.transform.position;
    P2 = Pos2.transform.position;

    ease(time,P1,P2);
    };

    Shai Benshoshan replied 7 years, 2 months ago 3 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    February 20, 2019 at 4:49 pm

    It looks like your expression will be running the entire loop each frame–there’s nothing telling it which layers it should be moving between on the current frame. Based on the current time, and the desired move time between layers, you need to calculate which layers you’re currently moving between, and how far along in that move you are. Something like this maybe:


    moveTime = 1;
    numberOfLayers = 4;
    idx = Math.floor(time/moveTime)+1;
    phase = time%moveTime;
    if (idx < numberOfLayers){
    P1 = thisComp.layer(idx).transform.position;
    P2 = thisComp.layer(idx+1).transform.position;
    ease(phase,0,moveTime,P1,P2);
    }else{
    thisComp.layer(numberOfLayers).transform.position;
    }

    Dan

  • Shai Benshoshan

    February 21, 2019 at 8:30 am

    thanks ☺

    So the If-else is functioning like a while-for loop?
    if (idx= 1, condition true ) {do X } else {do Y} ;
    what returns the idx++ ?

    thanks

  • Shai Benshoshan

    February 21, 2019 at 8:45 am

    It is working beautifully
    thanks:)

  • Andrei Popa

    February 21, 2019 at 9:19 am

    TIME. I remember having the same problem the first time i saw an expression. I was like how the hell does that thing iterate. It’s the time. Each frame, the time is different. And in order to make it an integer(time is float), you use Math.floor. Feel free to ask further explanations if you did not understand it.
    You can write this expression to the source text of a text layer to see exactly how it works.

    "time is:"+time+"\nand Math.floor(time) is:"+Math.floor(time)

    Andrei
    My Envato portfolio.

  • Shai Benshoshan

    February 21, 2019 at 3:19 pm

    Thank you Andrei :))
    I’ll try your way to figure it out
    It is a key concept/method in AE expression

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