Activity › Forums › Adobe After Effects Expressions › Stop and go (traffic jam, clock hands )
-
Stop and go (traffic jam, clock hands )
Posted by Roger Maus on July 13, 2012 at 1:17 amHi,
i am searching for an expression that makes a value “stop and go” between given keyframes.
It’s like in a traffic jam (or the hands of a clock): hold the value for some time, then catch up to make up the leeway. (The graph would look like stairs with inclined gain.)
There are a lot examples around in which the value *jump* to the next value, but theres no examples with a linear developement, not to mention *eased* change.
Any hints?
Roger Maus replied 13 years, 10 months ago 2 Members · 8 Replies -
8 Replies
-
Dan Ebberts
July 13, 2012 at 2:14 amThat would probably be something like this:
pct = .7;
if (numKeys > 1 && time >= key(1).time && time <= key(numKeys).time){
n = nearestKey(time).index;
if (key(n).time > time) n--;
t1 = key(n).time;
t2 = key(n+1).time;
v1 = key(n).value;
v2 = key(n+1).value;
t = time - t1;
ease(t,pct*(t2-t1),t2-t1,v1,v2);
}else
value
Set pct to the fraction of the time between keyframes that you want to hold the value of the first keyframe.
Dan
-
Roger Maus
July 13, 2012 at 2:42 amApart from the error that after effects gives me with this expression (something about “no such thing as a subsequent key”) I’m afraid I couldn’t make myself clear.
If I get it right, this expression makes the value wait at every key. But what I want is to give only the start and the end, and all the stop’n’goes inbetween beeing calculated:Only the key at the beginning and at the end is given, and so is t1 and t2.
(PS. the last stopping/recovery is depicted mistakingly. there’s half a “cycle” too much.) -
Dan Ebberts
July 13, 2012 at 3:19 amThis should be closer:
t1 = 1;
t2 = 1;if (numKeys > 1 && time > key(1).time && time < key(2).time){
span = key(2).time - key(1).time;
steps = Math.floor(span/(t1+t2));
valPerStep = (key(2).value - key(1).value)/steps;
curStep = Math.floor((time-key(1).time)/(t1+t2))
t = (time - key(1).time)%(t1+t2);
v1 = curStep*valPerStep;
ease(t,t1,t1+t2,v1,v1+valPerStep)
}else
value
Dan
-
Roger Maus
July 13, 2012 at 3:51 amAlmost perfect… it does what it should, but at the wrong position!
stopngo2.jpg
The object jumps to [0,0] to perform its jaggy movement, and in the end it jumps at its keyed postition… -
Dan Ebberts
July 13, 2012 at 4:56 amAh, yes. Try it this way:
t1 = 1;
t2 = 1;
if (numKeys > 1 && time > key(1).time && time < key(2).time){
span = key(2).time - key(1).time;
steps = Math.floor(span/(t1+t2));
valPerStep = (key(2).value - key(1).value)/steps;
curStep = Math.floor((time-key(1).time)/(t1+t2));
if (curStep < steps){
t = (time - key(1).time)%(t1+t2);
v1 = key(1).value + curStep*valPerStep;
ease(t,t1,t1+t2,v1,v1+valPerStep);
}else{
key(2).value;
}
}else
value
Dan
-
Roger Maus
July 13, 2012 at 1:40 pmThanks for all the effort, Dan…. I am sorry for beeing so helpless, and I feel kind of cheeky and picky…
but the problem pesists…
the erroneus expression in action. (different t1/t2 for the characters)
https://reels.creativecow.net/film/16812
and there’s a strange jump, too. -
Dan Ebberts
July 13, 2012 at 5:30 pmI’m not sure what’s going on. Do you have more than two keyframes? I did find a strange glitch where JavaScript’s modulo operator (%) gives incorrect results in some cases. That causes the jump you’re seeing. This version should correct that problem:
t1 = .5;
t2 = .3;
if (numKeys > 1 && time > key(1).time && time < key(2).time){
span = key(2).time - key(1).time;
steps = Math.floor(span/(t1+t2));
valPerStep = (key(2).value - key(1).value)/steps;
curStep = Math.floor((time-key(1).time)/(t1+t2));
if (curStep < steps){
t = (time-key(1).time)/(t1+t2) - curStep;
v1 = key(1).value + curStep*valPerStep;
ease(t,t1,t1+t2,v1,v1+valPerStep);
}else{
key(2).value;
}
}else
value
Dan
Reply to this Discussion! Login or Sign Up
