Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Begin an animation when a condition is met

  • Begin an animation when a condition is met

    Posted by Kevin Dazet on March 13, 2023 at 8:15 pm

    I’m trying to modify a blinking cursor typewriter/console animation. It uses this expression to cause the cursor to blink at all times:


    var s = effect(“Cursor Blink Speed”)(1);

    var blink = Math.sin(Math.PI*time*s);

    if(b == 1){
    (blink >= 0) * 100;
    }else{
    0;
    }


    However, I’m trying to get the animation to begin *exactly when* my text layer has finished animating on. I have a slider that controls the text animation completion. When the value of that slider has a speed of zero, it activates the blink animation. This almost works for me, but because the status of that blink animation is based on absolute time (so it’s like cutting to an animation that’s already in progress), it often blinks for only one or two frames when it’s triggered.


    What I’d like is for the sine function to begin its cycle right when the slider’s speed hits zero.


    I know expressions have no memory, so I don’t know if this is possible. Anyone have a solution?


    Brie Clayton replied 1 year, 1 month ago 3 Members · 4 Replies
  • 4 Replies
  • Filip Vandueren

    March 13, 2023 at 9:02 pm

    Hi Kevin, try something like this:

    const sl = effect("Animate On")("Slider");
    const s = effect("Cursor Blink Speed")(1).value;
    (function() {
    if (sl.numKeys<2) return 100
    if (sl.velocity>0) return 100
    t = sl.nearestKey(time).time;
    if (time<sl.key(1).time) {
    t=0;
    } else if (time<t){
    t = sl.key(sl.nearestKey(time).index-1).time;
    }
    return ((((time-t)*s)%1)<0.5)*100;
    })();

    I’m assuming the animating slider is only changed by keyframes, not by an expression ?

  • Kevin Dazet

    March 13, 2023 at 9:50 pm

    Amazing—it works! I’m trying to wrap my head around what you’ve done here, but it does do exactly what I wanted. Yes, the animation slider is controlled by keyframes.

    Thanks, Filip!

  • Filip Vandueren

    March 13, 2023 at 10:51 pm

    I simplified the final result, it doesn’t use Sin() but a modulo (because you were just blinking on/off, no need for trig functions and Pi)

    with sin, it would have also use (time-t)*s instead of time -> the offset t that is subtracted from time is in effect the time of the last keyframe we’ve passed, so the blinking now has relative time to the last keyframe.

    But the function starts off with the cases where we don’t need to bother with blinking: if there’s less than 2 keyframes (which could have been omitted, because those cases would mean velocity=0 anyway)

    And if the velocity of the slider is not at 0, the cursor is moving, and we return out of the function yielding 100% without doing the other calculations.

  • Brie Clayton

    March 14, 2023 at 2:01 pm

    Thank you, Kevin, for letting us know that Filip has solved your issue. In Creative COW’s new reward system, Filip has earned a COW Solve Coin.

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