-
.toWorld function with a 2D Point control
Hi everyone,
Let’s say I have 2 layers in a composition. A layer “A” with its position animated. And a layer “B” with its position linked with expression to Layer “A” ‘s position. Therefore, when A moves, B moves accordingly.
I wanted to make “B” overshoot its trajectory, for this, I used a fairly complicated expression. So far, so good, it works.BUT, I’d like to change the source of the position animation. It won’t be the position of layer “A” anymore, but a 2D Point control called “Point A” applied on layer “B”. This “Point A” is linked with expression to Layer “A” ‘s position.
So I replaced the .position property by .effect(“Point A”)(“Point”) but it doesn’t work. There is no bug in the Expression panel but the overshoot trajectory is gone…I’m wondering if I’m not missing something here?
freq = 3;
decay = 5;
v = [0,0]if (decay == 0) decay = 0.1;
if (freq == 0) freq = 0.1;
delay = freq/decay;
weight = 1/decay/10;
frameDur = thisComp.frameDuration;
function worldVelocity(TIME) {
worldVelocityX = (thisLayer.toWorld(thisLayer.position,TIME)[0]-thisLayer.toWorld(thisLayer.position,TIME-.01)[0])*100;
worldVelocityY = (thisLayer.toWorld(thisLayer.position,TIME)[1]-thisLayer.toWorld(thisLayer.position,TIME-.01)[1])*100;
return [worldVelocityX,worldVelocityY];
}
function worldSpeed(TIME) {
return length(worldVelocity(TIME));
}
timeStart = 0;
timeRestart = 0;
stop = false;
stopped = false;
for (i=timeToFrames(time);i>=0;i--) {
var t = framesToTime(i);
var tNext = t-frameDur;
if (worldSpeed(t) == 0 ) {
if (timeRestart == 0) timeRestart = t;
if (worldSpeed(tNext) !=0 ) {
timeStart = tNext;
break;
}
}
}
TIME = time-timeStart;
frameRestart = timeToFrames( time-timeRestart);
w = v
if ( frameRestart <= delay)
w = v - worldVelocity(time)*weight*(frameRestart/delay);
else
w = v - worldVelocity(time)*weight;
if (worldSpeed(time) == 0) {
spring = worldVelocity(timeStart) * ( .15/freq * Math.sin(freq * TIME * 2 * Math.PI) / Math.exp( TIME * decay ) );
w + spring + thisLayer.position;
}else{ w + thisLayer.position; }