Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Control Positional Drift with Sliders

  • Control Positional Drift with Sliders

    Posted by Casey Drogin on January 31, 2025 at 1:39 am

    Hello,

    I am trying to control a vertical drift on a layers Y-position. I want it to drift by 100 pixels every second via expression, which a simple time*100 would achieve. Further, I would like to slow this drift down to a complete stop in place, and then have the drift pick up again by keyframing a Slider controller.

    However, when I keyframe the slider value from 100 to 0, the position resets back to its starting point, and does not stay in place. Is there a modification to this expression that might achieve this?

    Thank you!

    Casey Drogin replied 2 weeks, 3 days ago 2 Members · 3 Replies
  • 3 Replies
  • Yoan Boisjoli

    January 31, 2025 at 1:48 am

    Hi Casey! The issue you’re facing is that when the slider is keyframed, the position calculation is always relative to the current time, which causes an abrupt jump instead of smoothly slowing down. Try this:

    spd = thisLayer.effect("Speed")("Slider");

    t0 = thisLayer.inPoint;

    accum = 0;

    n = spd.numKeys;

    if (n > 0 && spd.key(1).time < time) {

    accum = spd.key(1).value * (spd.key(1).time - t0);

    for (i = 2; i <= n; i++) {

    if (spd.key(i).time > time) break;

    k1 = spd.key(i - 1);

    k2 = spd.key(i);

    accum += (k1.value + k2.value) * (k2.time - k1.time) / 2;

    }

    accum += (spd.value + spd.key(i - 1).value) * (time - spd.key(i - 1).time) / 2;

    } else {

    accum = spd.value * (time - t0);

    }

    [value[0], value[1] + accum];

  • Yoan Boisjoli

    January 31, 2025 at 1:51 am

    if you’re interested, you can always learn more on Dan’s website here:

    https://www.motionscript.com/articles/speed-control.html

  • Casey Drogin

    January 31, 2025 at 3:07 am

    Yoan, this worked perfectly. The article you provided was fascinating, it really is a deceptively complicated problem! Thanks for the quick help.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy