-
Order of expression calculations – or link an already calculated expression
Hi, Ive run into a small “problem”. This is just for fun, but I wanted to have a small square “rolling” across my comp, so linking x-position and rotation in the correct way and calculating the y-position. This is what I came up with:
Position:
h=thisLayer.sourceRectAtTime().height/2;
x=value[0];
s=content("square_01").content("squarepath_01").size[1]/2;
[x,s-h]
Rotation:
s=content("square_01").content("squarepath_01").size[0]/100;
p=content("square_01").transform.position;
p/s
This works just fine. Now comes the tricky part: I wanted to add Dan Ebberts awesome Overshoot expression to the mix. This looks like this:
h=thisLayer.sourceRectAtTime().height/2;
x=value[0];
s=content("square_01").content("squarepath_01").size[1]/2;freq = 3;
decay = 5;
n = 0;
if (numKeys > 0){
n = nearestKey(time).index;
if (key(n).time > time) n--;
}
if (n > 0){
t = time - key(n).time;
amp = velocityAtTime(key(n).time - .001)[0];
w = freq*Math.PI*2;
[x + amp*(Math.sin(t*w)/Math.exp(decay*t)/w),s-h];
}else
[x,s-h]
This gives the position a nice overshoot. But as soon as the playhead “leaves” the keyframed area and the x position is only calculated by the expression, the linked rotation does not work anymore/ stays at the value corresponding to the last keyframe. I worked around this problem by calculating the x-overshoot again in the rotation-expression, but it seems wrong to me that you have to calculate this twice.So my question is: Is there a way to link a value with the calculations made by expressions?