Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions How to start an animation on event?

  • How to start an animation on event?

    Posted by Taras Kosmachuk on November 14, 2013 at 7:28 pm

    Hi!
    I have a layer with an animation and a null object. I need to set the animation to start when the null passes anchor point of the layer on x axis…
    Here’s the overall algorithm that I’m using but the problem is that I don’t know how to find the time when above condition happens!

    nullObject = thisComp.layer(“null”);

    nullObject = nullObject.toWorld(nullObject.anchorPoint);
    layPos = thisLayer.toWorld(thisLayer.anchorPoint);
    trackValue = layPos[0]-nullObject[0];

    if (trackValue <= 0) {
    t = ??? // algorithm to find time…
    } else {
    t = time;
    }

    value=value.atTime(t);

    Can anyone help me with this?
    Thanks in advance!

    Taras Kosmachuk replied 12 years, 6 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    November 14, 2013 at 8:47 pm

    Your expression needs to start at the current frame and go back in time frame-by-frame, until you find the most recent frame where the null’s x went from being less than the target x to more than the target x. Then subtract the time of that frame from the current time to determine how long your animation has been running.

    It’s really just a threshold detector along the lines of this beat detector:

    https://www.motionscript.com/design-guide/audio-trigger.html

    Dan

  • Taras Kosmachuk

    November 19, 2013 at 1:07 am

    Hi Dan! Thanks for helping me out!

    I’ve adapted your expression to my needs and it seems to be correct, it should return time when layer x position is less or equal to null x position… But ae returns an error:

    “Function trackValue.valueAtTime is undefined”

    What am I doing wrong?

    goalNull = thisComp.layer("null");

    goalPos = goalNull.toWorld(goalNull.anchorPoint);
    layPos = thisLayer.toWorld(thisLayer.anchorPoint);
    trackValue = layPos[0]-goalPos[0];

    check = false;
    for (f = 0; f &lt;= timeToFrames(); f++){
    t = framesToTime(f);
    if (trackValue.valueAtTime(t) &lt;= 0 ){
    check = true;
    break;
    }
    }
    if (check)
    t;
    else
    time;

  • Dan Ebberts

    November 19, 2013 at 1:57 am

    I haven’t tested this, but I think you need to move some of your code inside the loop and use the time parameter of toWorld() to get the time-appropriate values:


    goalNull = thisComp.layer("null");
    check = false;
    for (f = 0; f <= timeToFrames(); f++){
    t = framesToTime(f);
    goalPos = goalNull.toWorld(goalNull.anchorPoint,t);
    layPos = toWorld(anchorPoint,t);
    trackValue = layPos[0]-goalPos[0];
    if (trackValue <= 0 ){
    check = true;
    break;
    }
    }
    if (check) t else time;

    Dan

  • Taras Kosmachuk

    November 19, 2013 at 2:49 am

    It works just perfect! Thanks a lot!

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