Copy link to clipboard
Copied
Hi.
I have a problem where I would like to control Offset in time and Inertial Bounce Expressions together on a layer which is connected to a null. Here is my expression so far:
// Expression below makes the Offset in time
offset = thisComp.layer("CONTROL LAYERS").effect("Slider Control")("Slider"); //The offset in time, negative half a second.
p = thisComp.layer("Null 12"); //The parent layer
T = time + offset; //The current time minus half a second
p.position.valueAtTime(T); //Value of the parent's position property at the current time minus half a second
// Expression below makes the Inertial Bounce
x = thisComp.layer("Null 12").transform.position;
n = 0;
if (x.numKeys > 0){
n = x.nearestKey(time).index;
if (x.key(n).time > time) n--;
}
if (n == 0){
t = 0;
}else{
t = time - x.key(n).time;
}
if (n > 0){
v = x.velocityAtTime(x.key(n).time - thisComp.frameDuration/10);
amp = .02;
freq = 2.0;
decay = 4;
x.value + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);
}else{
x.value;
}
Any Idea how to make these two expressions work sametime together?
-Matti
It's going to end being something close to this, where you work variable T in instead of "time" in the second expression and use x.valueAtTime(T) instead of x.value:
offset = thisComp.layer("CONTROL LAYERS").effect("Slider Control")("Slider");
p = thisComp.layer("Null 12"); //The parent layer
T = time + offset;
x = p.transform.position;
n = 0;
if (x.numKeys > 0){
n = x.nearestKey(T).index;
if (x.key(n).time > T) n--;
}
if (n == 0){
t = 0;
}else{
t = T - x.key(n).time;
}
if (n > 0){
v = x.velocityAtTi
...Copy link to clipboard
Copied
You would have to completely restructure/ rewrite them, beginning with the fact that expressions evaluate in strict order, which makes your code as it is already false - the bounce needs to happen before you actually can shift it in time. And in this case you can't use valueAtTime(), anyway, because there are no pre-existing values that could be remapped, so the time offset stuff is useless, anyway. Instead you would have to manipulate the key() times and base your calculations thereon. Otherwise nothing is stopping you from just padding out your structure/ animation hierarchy. For all intents and purposes, what would be the hold-up to calculate the bounce on yet another extra Null and then reference that Null? Takes care of every problem plus has the advantage that it would avoid further extensive and slow temporal calculations, which would be the other problem. Even if one were to modify the expression, it would inevitably already end up being a lot slower due to AE not being able to store persistent data and thus having to re-evaluate the code for every frame. the larger the temporal offset, the more extra frames AE would have to calculate over and over again. So why noit keep things simple? you have a clear ansd straightforward alternative here.
Mylenium
Copy link to clipboard
Copied
It's going to end being something close to this, where you work variable T in instead of "time" in the second expression and use x.valueAtTime(T) instead of x.value:
offset = thisComp.layer("CONTROL LAYERS").effect("Slider Control")("Slider");
p = thisComp.layer("Null 12"); //The parent layer
T = time + offset;
x = p.transform.position;
n = 0;
if (x.numKeys > 0){
n = x.nearestKey(T).index;
if (x.key(n).time > T) n--;
}
if (n == 0){
t = 0;
}else{
t = T - x.key(n).time;
}
if (n > 0){
v = x.velocityAtTime(x.key(n).time - thisComp.frameDuration/10);
amp = .02;
freq = 2.0;
decay = 4;
x.valueAtTime(T) + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);
}else{
x.valueAtTime(T);
}
Dan
Copy link to clipboard
Copied
Thanks Dan and Mylenium for your answers. I think Dan that your reply did the trick pretty much I wished for.
Thanks.
-Matti
Find more inspiration, events, and resources on the new Adobe Community
Explore Now