ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

.toWorld function with a 2D Point control

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Remi Monedi
.toWorld function with a 2D Point control
on Mar 3, 2020 at 5:48:38 pm

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 &lt;= 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; }


Return to posts index

Alex Printz
Re: .toWorld function with a 2D Point control
on Mar 3, 2020 at 9:02:14 pm

Can you first get this to work without the overshoot element of the script? I'm not sure what was added before and after the overshooting script, as that is (likely) the problem.

Alex Printz
Mograph Designer


Return to posts index

Remi Monedi
Re: .toWorld function with a 2D Point control
on Mar 4, 2020 at 9:34:33 am

Hi Alex!

I only use this expression with copy/paste, not using a script and it works fine (without me trying to modify it for 2D Point problem). But you're right, it comes from an old version of the script Duik.
So you think that this expression uses function only described in the script file or something like that?
I didn't think of this because the expression as itself is working without the use of the script.


Return to posts index


Alex Printz
Re: .toWorld function with a 2D Point control
on Mar 5, 2020 at 6:12:32 pm

No what I'm suggesting is that the expression is dependent on some properties that aren't passing through a toWorld function, so that it's not registering correctly.

Can you highlight the changes you made before and after the toWorld was added? You may need to parse some of the data back through a fromWorld or something similar.

Alex Printz
Mograph Designer


Return to posts index

Remi Monedi
Re: .toWorld function with a 2D Point control
on Mar 6, 2020 at 9:28:47 am

Hi Alex,

The original expression already has the toWorld function, here is the expression :

decay = 5;
freq = 3;
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.anchorPoint,TIME)[0]-thisLayer.toWorld(thisLayer.anchorPoint,TIME-.01)[0])*100;
worldVelocityY = (thisLayer.toWorld(thisLayer.anchorPoint,TIME)[1]-thisLayer.toWorld(thisLayer.anchorPoint,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 = value
if ( frameRestart &lt;= delay)
w = value - worldVelocity(time)*weight*(frameRestart/delay);
else
w = value - 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;
}else{ w; }


And here is the same expression with my changes in bold :

decay = 5;
freq = 3;
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) {
<b>worldVelocityX = (thisComp.layer("A").toWorld(thisComp.layer("A").position,TIME)[0]-thisComp.layer("A").toWorld(thisComp.layer("A").position,TIME-.01)[0])*100;
worldVelocityY = (thisComp.layer("A").toWorld(thisComp.layer("A").position,TIME)[1]-thisComp.layer("A").toWorld(thisComp.layer("A").position,TIME-.01)[1])*100;</b>
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 = value
if ( frameRestart &lt;= delay)
w = value - worldVelocity(time)*weight*(frameRestart/delay);
else
w = value - 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 + thisComp.layer("A").transform.position;
<b>}else{ w + thisComp.layer("A").transform.position; }</b>


Return to posts index

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