Activity › Forums › Adobe After Effects Expressions › Increase position with comp markers
-
Increase position with comp markers
Posted by David Cabestany on October 2, 2017 at 8:36 pmI’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
David Cabestany replied 8 years, 10 months ago 2 Members · 7 Replies -
7 Replies
-
Dan Ebberts
October 2, 2017 at 10:42 pmSomething like this maybe:
sx = 100; // slide distance
sd = .25; // slide durationm = 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
-
David Cabestany
October 2, 2017 at 11:13 pmThis 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. -
Dan Ebberts
October 2, 2017 at 11:20 pmIf you just want it to jump at each marker, you could do it like this:
sx = 100; // jump distancem = 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
-
David Cabestany
October 6, 2017 at 2:41 amHey 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,
-
Dan Ebberts
October 6, 2017 at 3:30 amSomething 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
Reply to this Discussion! Login or Sign Up