ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Increase position with comp markers

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
David Cabestany
Increase position with comp markers
on Oct 2, 2017 at 8:36:17 pm

I'd like to sync the movement of a layer with the markers of a comp, which in turn I'm already using to increment the value of a repeater on a shape layer.

Basically I need for the layer to slide x amount of pixels each time it passes a marker.
Is it possible?

Thanks


Return to posts index

Dan Ebberts
Re: Increase position with comp markers
on Oct 2, 2017 at 10:42:36 pm

Something like this maybe:


sx = 100; // slide distance
sd = .25; // slide duration

m = thisComp.marker;
x = 0;
if (m.numKeys > 0){
n = m.nearestKey(time).index;
if (time < m.key(n).time) n--;
if (n > 0){
t = time - m.key(n).time;
x = ease(t,0,sd,(n-1)*sx,n*sx);
}
}
value + [x,0]


Dan



Return to posts index

David Cabestany
Re: Increase position with comp markers
on Oct 2, 2017 at 11:13:05 pm

This is perfect Dan, thanks.
All I changed was the slide duration to 0, so the movement is more like hold keyframes.

One question, though, on the value of n you subtract one unit each time the marker increases its value, since the markers are always increasing its value why is n not adding a unit after each loop, in other words why the expression isn't n++ instead of n--?

Thanks again,
D.


Return to posts index


Dan Ebberts
Re: Increase position with comp markers
on Oct 2, 2017 at 11:20:41 pm

If you just want it to jump at each marker, you could do it like this:


sx = 100; // jump distance

m = thisComp.marker;
x = 0;
if (m.numKeys > 0){
n = m.nearestKey(time).index;
if (time < m.key(n).time) n--;
x = n*sx;
}
value + [x,0]


As to your other question, there is no loop. The algorithm is just finding the most recent, previous marker. The n-- happens only when nearestKey() returns the next marker, instead of the previous one (when the current time is closer to the marker on its right than it is to the one on its left).

Dan



Return to posts index

David Cabestany
Re: Increase position with comp markers
on Oct 3, 2017 at 7:09:51 pm

Thanks a lot for the explanation Dan.


Return to posts index

David Cabestany
Re: Increase position with comp markers
on Oct 6, 2017 at 2:41:05 am

Hey Dan, wondering if you could help me to further enhance this expression.

I'm using it now to displace the y value instead of the x, but the jumps need to be irregular, meaning some times it needs to jump 55 pixels and others 110.

I added a slider to control the sx variable and keyframed the value using hold keyframes, the first jumps were ok, at first it moved 55 pixels and then 110, however when I need it to go back to 55 pixels per increment, it went down instead of jumping up as it was doing before.

Can you help me so it always goes in one direction?

Thanks,


Return to posts index


Dan Ebberts
Re: Increase position with comp markers
on Oct 6, 2017 at 3:30:23 am

Something like this maybe:


sy = effect("Slider Control")("Slider");

m = thisComp.marker;
y = 0;
if (m.numKeys > 0){
n = m.nearestKey(time).index;
if (time < m.key(n).time) n--;
for (i = 1; i <= n; i++){
y += sy.valueAtTime(m.key(i).time);
}
}
value + [0,y]



Dan



Return to posts index

David Cabestany
Re: Increase position with comp markers
on Oct 6, 2017 at 8:53:18 pm

Just saw this. It's perfect, thanks so much.


Return to posts index

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