Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Oscilate y based on x velocity

  • Oscilate y based on x velocity

    Posted by Andres Torres on September 16, 2012 at 8:27 pm

    I’d like to create an expression that will move y pos up and down based on x velocity. So the faster the object moves in x, the faster and larger the oscillations. The object would look like it was on a floor so the y pos wouldn’t go below zero.

    Thanks.

    Andres Torres replied 13 years, 10 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    September 16, 2012 at 11:44 pm

    It gets tricky any time you try to control speed or frequency. If you’re using linear keyframes, you can use a modified linear keyframe integrator:


    amp = 50;
    freqMult = .05;

    n = numKeys;
    i = 0;
    if (n > 0 && key(1).time < time){
    accum = velocityAtTime(key(1).time)[0]*(key(1).time - inPoint);
    for (i = 2; i <= n; i++){
    if (key(i).time > time) break;
    k1 = key(i-1);
    k2 = key(i);
    accum += (velocityAtTime(k1.time)[0] + velocityAtTime(k2.time - .001)[0])*(k2.time - k1.time)/2;
    }
    accum += (velocity[0] + velocityAtTime(key(i-1).time + .001)[0])*(time - key(i-1).time)/2;
    }else{
    accum = velocityAtTime(inPoint)[0]*(time - inPoint);
    }
    y = amp*Math.abs(Math.sin(accum*freqMult));
    value - [0,y]

    Dan

  • Andres Torres

    September 17, 2012 at 2:01 am

    Works great, thanks.

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