Adobe After Effects Expressions Forum
Dynamically targeting layers with the index property
Dynamically targeting layers with the index property
by Sohrab Golestani on Jun 20, 2019 at 10:00:25 pm

I have a .png that has been split up into a grid of segments using Utility Box v1.6 - each segment is one composition/layer. I want to scramble the image by rearranging the segments randomly. To do so, I rearranged the layers randomly, and I want to use an ease expression to move the layer from its existing position to the position of the layer under it:

ease(time, 0, 2, value, thisComp.layer(index + 1).transform.position)

This works great when I put it on layer 1 - it moves from its position to the position of layer 2 over 2 seconds. Great.

When I copy that expression to layer 2, both layer 1 and layer 2 move to layer 3's position.

Is there a way to get after effects to evaluate the expressions independently?

Thanks,

ease(time, 0, 2, value, thisComp.layer(index + 1).transform.position)


Re: Dynamically targeting layers with the index property
by Oleg Pirogov on Jun 21, 2019 at 6:42:21 am

You're telling layer 1 to move where layer 2 is ([...].transform.position). So, since layer 2 goes to layer 3, layer 1 also goes there.
Instead, you'd wanna layer 1 to go to former position of layer 2, so [...].transform.position.valueAtTime(0) may be the solution:

ease(time, 0, 2, value, thisComp.layer(index + 1).transform.position.valueAtTime(0))

P.S. [...](0) - zero here is "the time when layer 2 was at the position you want layer 2 to go to". If it's some other time in your case, you should change it accordingly.


Re: Dynamically targeting layers with the index property
by Sohrab Golestani on Jun 21, 2019 at 2:11:53 pm

That did the trick, thank you!





© CreativeCOW.net