Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Triggering movement of an object by a sound in another comp

  • Triggering movement of an object by a sound in another comp

    Posted by Patrick Dunn on September 29, 2012 at 4:48 pm

    Hi – I’m a bit stuck on this. What I’m trying to do is set up a situation where when soundkeys hits a particular level/output (e.g. 100) the position of an object in another comp (actually it’ll be many many comps in the end) moves from 0 to 100. I want the object to start moving a second before the sound hits 100. I’ve no problem “looking forward” 1 second (using valueAtTime) and getting the data out of the other comp, and triggering a crude movement, but I want it to be a gradual shift of position.

    I’d thought I’d be able to use a persistent variable (x = x + 1 etc.) but I can’t. I’ve looked at the various “x = x + 1” postings on here and I’m sorry, I don’t understand them.

    Can anyone help?

    Thanks – Patrick

    Dan Ebberts replied 13 years, 11 months ago 2 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    September 29, 2012 at 5:59 pm

    This might help. This will scan the audio layer from its In Point, look for the first frame where the value reaches the threshold (100 in this case). If it finds one, it will ease the x position of the layer to the right, starting one second before the threshold is hit.


    threshold = 100;
    prerun = 1;
    moveDur = 1; // duration of move
    moveDist = 100; // x distance of move

    L = comp("audio comp").layer("audio layer");
    aud = L.effect("Sound Keys")("Output 1");
    trigger = false;

    t=L.inPoint;
    while (t < L.outPoint){
    if (aud.valueAtTime(t) >= threshold){
    trigger = true;
    break;
    }
    t += thisComp.frameDuration;
    }
    if (trigger)
    x = ease (time,t-prerun,t-prerun+moveDur,0,moveDist)
    else
    x = 0;
    value + [x,0]

    Dan

  • Patrick Dunn

    September 29, 2012 at 9:52 pm

    wow! That’s amazing – thanks so much. I’ve fiddled with it a bit, got it moving up and down and stuff. I kind of 80% understand it and I’ll fiddle to see if I can work out how to make it react/move for every instance of the 100 peak.

    Thanks again – Patrick

  • Dan Ebberts

    September 30, 2012 at 12:18 am

    If you want to trigger an animation everytime the value reaches 100, you should look at this (if you haven’t already):

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

    If you want the animation to be cumulative, you’ll need to incorporate some logic like my beat counter has to calucate how much movement has occurred due to previous triggers:

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

    Lack of persistent data in expressions does make things complicated. 🙂

    Dan

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