Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Trigger In and Out animation with comps markers

  • Trigger In and Out animation with comps markers

    Posted by Dario De angelis on May 26, 2020 at 4:57 pm

    Hi guys, I’ve searched all the forum to my answer but I didn’t find it.

    I’m working on an interface animation, and I need to find a way to trigger an animation (there two simply ease keyframe) of an UI’s elements.
    When the cursor passes on it expands, when the cursor leaves it collapse.

    I’ve set two keyframes (some layers have scale, some position) at the start of my layers and used this expression to trigger the animation’s keyframes from the first to the second.
    n = thisComp.marker.nearestKey(time).index;
    if (time < thisComp.marker.key(n).time){
    n = n-1;
    }
    if(n==0){
    n = 1
    }
    t = time - thisComp.marker.key(n).time;
    thisProperty.valueAtTime(t)

    So the struggle now is to return from the second keyframe to the first. There is a way to do it with expressions?

    Dario De angelis replied 5 years, 11 months ago 2 Members · 6 Replies
  • 6 Replies
  • Dan Ebberts

    May 26, 2020 at 6:45 pm

    I’m not sure if this is what you’re after, but give it a try:


    m = thisComp.marker;
    t = 0;
    if (numKeys > 1 && m.numKeys > 0){
    d = key(2).time - key(1).time;
    tm = m.nearestKey(time).time;
    if (time < tm){
    t = linear(time,tm-d,tm,key(1).time,key(2).time)
    }else{
    t = linear(time,tm,tm+d,key(2).time,key(1).time)
    }
    }
    valueAtTime(t)

    Dan

  • Dan Ebberts

    May 26, 2020 at 7:51 pm

    If you want the whole animation triggered at each marker (rather than centered at each marker), it would be more like this:


    m = thisComp.marker;
    t = 0;
    if (numKeys > 1 && m.numKeys > 0){
    d = key(2).time - key(1).time;
    n = m.nearestKey(time).index;
    if (time < m.key(n).time) n--;
    if (n > 0){
    tm = time - m.key(n).time;
    if (tm < d){
    t = linear(tm,0,d,key(1).time,key(2).time);
    }else{
    t = linear(tm,d,d*d,key(2).time,key(1).time);
    }

    }
    }
    valueAtTime(t)

    Dan

  • Dario De angelis

    May 27, 2020 at 11:05 am

    Thanks Dan.

    The first expression you posted do (more or less) what I want.
    The issue is that the In and Out are consequential:
    time hit the first marker and animation goes from KFrame1—K2—K1, then hit the second marker and again, from K1—K2—K1.

    What I would like is:
    time hit the first marker: animation goes from K1—K2 then stay to K2 position/scale/rotation value until time hit the second marker, then the animation goes to K2—K1.

    (Sorry for my bad english, it’s not my native language)

  • Dario De angelis

    May 27, 2020 at 11:46 am

    Sorry, my bad.

    The first expression doesn’t do that:

    “time hit the first marker and animation goes from KFrame1—K2—K1, then hit the second marker and again, from K1—K2—K1.”

    but

    animation is 10f long, so, time goes 10f before the marker, animation start from K1, then when hit the marker animation is on K2 value and then 10f later on the K1.
    So it’s pretty like:
    00——10(M)—-20
    K1——K2———K1

  • Dan Ebberts

    May 27, 2020 at 3:18 pm

    Something like this should work as long as the markers are farther apart than the keyframes:


    m = thisComp.marker;
    t = 0;
    if (numKeys > 1 && m.numKeys > 0){
    n = m.nearestKey(time).index;
    if (time < m.key(n).time) n--;
    if (n == 1)
    t = key(1).time + time - m.key(1).time
    else if (n == 2)
    t = key(2).time - (time - m.key(2).time);
    }
    valueAtTime(t)

  • Dario De angelis

    May 27, 2020 at 3:24 pm

    You’re the greatest of all time.
    Works like a charm.

    BIG THANKS!

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