ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

what drives the expression to loop ?

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Shai Benshoshan
what drives the expression to loop ?
on Feb 20, 2019 at 12:07:11 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 Pos1 = thisComp.layer(i);
Pos2 = thisComp.layer(i+1);
P1 = Pos1.transform.position;
P2 = Pos2.transform.position;
ease(time,P1,P2);
};

thanks:)





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);
};


Return to posts index

Dan Ebberts
Re: what drives the expression to loop ?
on Feb 20, 2019 at 4:49:05 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



Return to posts index

Shai Benshoshan
Re: what drives the expression to loop ?
on Feb 21, 2019 at 8:30:54 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


Return to posts index


Shai Benshoshan
Re: what drives the expression to loop ?
on Feb 21, 2019 at 8:45:15 am

It is working beautifully
thanks:)


Return to posts index

Andrei Popa
Re: what drives the expression to loop ?
on Feb 21, 2019 at 9:19:09 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.


Return to posts index

Shai Benshoshan
Re: what drives the expression to loop ?
on Feb 21, 2019 at 3:19:41 pm

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


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]