Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions surprised by sporatic result in expression

  • surprised by sporatic result in expression

    Posted by Jay Ingles on January 7, 2010 at 12:54 am

    Hi everyone.

    I’m using the code below to make a wing flap.

    The problem is when i ramp the sliders up it the wing goes crazy until it hits its destination frequency/amplitude.

    Does anyone have any idea why? Does it need to calculate integers and not decimals? my sliders are as follows:

    frequency: 0.32 -> 3.3
    amplitude: 10 -> 77

    Also, how would i add in the ease(…) code to it?

    Thanks!
    /jay

    (ps, the decay element is not needed in the expression)

    freq = thisComp.layer("Null: Angle Wing Slider").effect("Frequency Slider")("Slider");
    amplitude = thisComp.layer("Null: Angle Wing Slider").effect("Amplitude Slider")("Slider");
    decay = 0; //no decay

    amplitude*Math.sin(freq*time*2*Math.PI)

    jay

    Dan Ebberts replied 16 years, 4 months ago 2 Members · 1 Reply
  • 1 Reply
  • Dan Ebberts

    January 7, 2010 at 4:01 am

    It’s hard to explain, but any time you try and change the speed or frequency of an expression you can run into trouble. In this case, because expressions have no info about what has happened in the past, at each frame the calculation behaves as if the frequency has always been at the current value. This can cause discontinuities, speeding up and slowing down, until the frequency stabilizes.

    One approach is to create a loop that integrates how much the frequency at each frame affects the total phase angle of the wave. This isn’t a great solution for a long piece, because the calculation takes longer at each frame, but it works OK for short pieces. Try this:

    freq = thisComp.layer(“Null: Angle Wing Slider”).effect(“Frequency Slider”)(“Slider”);
    amplitude = thisComp.layer(“Null: Angle Wing Slider”).effect(“Amplitude Slider”)(“Slider”);

    phase = 0;
    f = timeToFrames(time);
    for (i = 1; i <= f; i++){ phase += (thisComp.frameDuration*freq.valueAtTime(framesToTime(i)))*Math.PI*2; } amplitude*Math.sin(phase) Dan

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