Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Making expression start at a certain time.

  • Making expression start at a certain time.

    Posted by John Winthrop on September 29, 2016 at 3:29 pm

    This question isn’t so much about accomplishing something as it is me trying to understand the coding language.

    I am using this common expression for a rotation pendulum effect.
    ——————————-
    veloc = 7;
    amplitude = 80;
    decay = .7;

    amplitude*Math.sin(veloc*time)/Math.exp(decay*time)
    ————————————–

    I wanted it to start at 5 seconds of my composition so I added this conditional:

    —————————————
    if (time>5) {(the expression above)}
    —————————————

    The problem was that because the pendulum expression uses the time as its input by the time 5 seconds has arrived the rotation has almost decayed entirely, so it just jumps to the end.

    To get around this I thought for a second and on a whime I added “-5” at the end of the two TIME values in the equation:

    ————————————————————–
    If (time>5)
    {
    veloc = 7;
    amplitude = 80;
    decay = .7;

    amplitude*Math.sin(veloc*time-5)/Math.exp(decay*time-5)
    }
    ——————————————————————————–

    In short, it worked like a charm!
    My question: is this the most practical way to achieve this result? I am very new to coding and while there is a ton of help out there nobody talked about this particular problem.

    Is there a way to write the expression so that the value for “time” in the swing equation starts whenever the conditional starts?

    Dan Ebberts replied 9 years, 7 months ago 2 Members · 7 Replies
  • 7 Replies
  • Dan Ebberts

    September 29, 2016 at 4:11 pm

    I think I’d do it this way:

    tStart = 5;
    veloc = 7;
    amplitude = 80;
    decay = .7;
    t = Math.max(time-tStart,0);
    amplitude*Math.sin(veloc*t)/Math.exp(decay*t)

    Dan

  • John Winthrop

    September 29, 2016 at 6:16 pm

    That works perfectly. Can I ask a bit about why it works?

    It seems you replaced “time-(whatever value i start at)” with the variable “t” and defined t as “time-(whatever time i want to start at)” so you can change the tStart value instead of changing the -5 everytime.

    But what exactly does the Math.max function do? I don’t understand how defining tStart makes the expression start only at that time.

  • Dan Ebberts

    September 29, 2016 at 6:29 pm

    Math.max() clamps the value of t at zero until time is greater than tStart. Then t becomes time-tStart.

    Dan

  • John Winthrop

    September 30, 2016 at 2:44 pm

    Okay.

    If it isn’t too much trouble can you give me a different maybe simpler example of how to use “Math.max”/”Math.min”?

    I have been trying to wrap my head around your equation and it’s over my head. Thank you for your help I am really enjoying expressions.

  • Dan Ebberts

    September 30, 2016 at 4:31 pm

    Math.max(0,-2,5) // result is 5

    Math.min(0,-2,5) // result is -2

    Dan

  • John Winthrop

    September 30, 2016 at 6:27 pm

    Okay, I think I understand but just to make sure I understand can you confirm (last post I promise).

    So Math.max simply looks through your values (provided in the parenthesis separated by commas), and outputs the highest one? (Math.min I assume outputs the lowest)

    So applying Math.max to variables that change over time tells your Math.max to become the highest number at any given point?

    So in your equation “t” is defined as either “time-5″ or 0” depending on which is larger.

    So at
    1 second >>> 1-5=-4 >>> 0 is the larger number >>> output 0.

    2 Seconds >>> 2-5=-3 >>> 0 is the larger number >>> output 0.
    …..
    ……
    …….
    5.1 seconds >>> 5.1-5=0.1 >>> 0.1 is the larger number >>> Output 0.1 as the rotation value

    And defining tStart allows you to easily change all the variables at once depending on your time needs.

    If I understand correctly that is GENIUS!!! Thank you so much for your help!

  • Dan Ebberts

    September 30, 2016 at 7:36 pm

    Sounds like you’ve got it!

    Dan

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