Copy link to clipboard
Copied
I thought I had done this before, but I can't figure it out again.
I have four position keyframes on a reference layer. I want to drive another property on another layer using an Ease interpolation method twice, so the moves are in opposite directions. Did you follow that?
When I only have 2 keyframes, this expression moves a shape layer background from the left edge of the screen until it fits under the moving text layer as the text layer (ref) moves from right to left.
ref = thisComp.layer(index -1);
hPad = effect("X Pad")("Slider");
refP = ref.position;
box = ref.sourceRectAtTime();
xSize = content("Rectangle 1").content("Rectangle Path 1").size[0];
totWidth = box.width + box.left;
if(refP.numKeys < 2)
value;
if(refP.numKeys == 2){
t = time;
tMin = refP.key(1).time
tMax = refP.key(2).time;
value1 = refP[0] - totWidth - hPad/2;
value2 = value1 + xSize;
mov = linear(t, tMin, tMax, value1, value2) - refP[0];
}
[mov, refP[1]]
I need to add two more position keyframes to the ref layer to move it back to the right and have the shape layer move back to the left. The second part of the ease expression would look like this:
{
t = time;
tMin = refP.key(3).time;
tMax = refP.key(4).time;
value1 = refP[0] - totWidth - hPad/2;
value2 = value1 + xSize;
mov = ease(t, tMin, tMax, value2, value1) - refP[0];
}
[mov, refP[1]]
I have been fiddling around with this for about an hour. I can make the shape layer move in or move out, but I can't get it to move in, stay for a while, and then move out.
Any help would be appreciated. If anybody knows, it is Dan Ebberts.
Rick, I haven't tested this, but I think you just need to test time vs. the 2nd keyframe time, like this:
ref = thisComp.layer(index -1);
hPad = effect("X Pad")("Slider");
refP = ref.position;
box = ref.sourceRectAtTime();
xSize = content("Rectangle 1").content("Rectangle Path 1").size[0];
totWidth = box.width + box.left;
if(refP.numKeys < 2)
value;
t = time;
if (t < refP.key(2).time){
tMin = refP.key(1).time
tMax = refP.key(2).time;
value1 = refP[0] - totWidth - hPad/2;
value2 = value1
...
Copy link to clipboard
Copied
You need to normalize the values to fall in ranges between 0 and 1, then you can add and multiply them with the distances. See my example from a two weeks ago that uses this methodology to combine different interpolators:
Mylenium
Copy link to clipboard
Copied
Rick, I haven't tested this, but I think you just need to test time vs. the 2nd keyframe time, like this:
ref = thisComp.layer(index -1);
hPad = effect("X Pad")("Slider");
refP = ref.position;
box = ref.sourceRectAtTime();
xSize = content("Rectangle 1").content("Rectangle Path 1").size[0];
totWidth = box.width + box.left;
if(refP.numKeys < 2)
value;
t = time;
if (t < refP.key(2).time){
tMin = refP.key(1).time
tMax = refP.key(2).time;
value1 = refP[0] - totWidth - hPad/2;
value2 = value1 + xSize;
mov = linear(t, tMin, tMax, value1, value2) - refP[0];
}else{
tMin = refP.key(3).time;
tMax = refP.key(4).time;
value1 = refP[0] - totWidth - hPad/2;
value2 = value1 + xSize;
mov = ease(t, tMin, tMax, value2, value1) - refP[0];
}
[mov, refP[1]]
Copy link to clipboard
Copied
Thank you Mylenium, and Dan Ebberts. Dan, you nailed it. I was making things too complicated, as is my usual workflow.
Thanks again. I. uploaded a project file if you're interested.