Skip to main content
Participant
February 26, 2025
Question

Help With a script

  • February 26, 2025
  • 1 reply
  • 121 views

I have two text layers, (Text 1 and Text 2) each is controlled by Slider to change the text, now the script work as it swap their position the higher number always remain at top, but if someone can help the position swap too quick, how can i easy ease them, like it change in 5 frames 

script :

slider1 = thisComp.layer("Text 1").effect("Slider 1")("Slider")
slider2 = thisComp.layer("Text 2").effect("Slider 2")("Slider")


originalPos1 = [value[0], 1002.753];
originalPos2 = [value[0], 1349.9595];

// Determine target position based on slider values
targetPos = (slider2 > slider1) ? originalPos1 : (slider2 < slider1 ? originalPos2 : value);

// Smooth transition
smoothTime = 2; // Adjust for slower or faster transition
currentTime = time;
previousPos = valueAtTime(currentTime - smoothTime);

linear(currentTime, currentTime - smoothTime, currentTime, previousPos, targetPos);

1 reply

ShiveringCactus
Community Expert
Community Expert
February 26, 2025

Have you tried:

ease(currentTime, currentTime - smoothTime, currentTime, previousPos, targetPos);

If you need a more specific duration, I think it's possible, but takes a bit of digging out the code.

 

 

 

ShiveringCactus
Community Expert
Community Expert
February 26, 2025

I've just recreated your comp, and yeah, ease will not work.  But I can see the issue with your current code.

With expressions, each frame runs the code as new, so in the linear function, currentTime is always updating.  

Where you have currentTime - smoothTime, that's always going to be 2 seconds from the currentTime now.   You need to figure out a fixed moment in the timeline to drive the linear expression (then the ease() function might improve things afterwards).

 

 

ShiveringCactus
Community Expert
Community Expert
February 26, 2025

OK, this is got my attention.

Turns out when checking the documentation ,you don't need time values for the linear or ease expressions:

https://helpx.adobe.com/uk/after-effects/using/expression-language-reference.html

 

You can just write:

ease(time, previousPos, targetPos);

But it was only working on the first value change. 

previousPos = transform.position.valueAtTime(time - smoothTime);

I think this problem is connected to this comparison line:

targetPos = (slider2 > slider1) ? originalPos1 : (slider2 < slider1 ? originalPos2 : tempVal);

As the change is happening during the 2 second window of smoothtime