Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions animating position at fixed intervals with fixed values

  • animating position at fixed intervals with fixed values

    Posted by Jonathan Reyes on December 1, 2009 at 2:44 pm

    Hello,
    I was wondering if there was an expression that can move a layer 5 points up in the y axis, pause for 2 seconds, then move up 5 points up again, pause for 2 seconds, move 5 points up, etc. I also want this to animate moving 5 points up rather than having an instant jump. any thoughts if this is possible? thanks!

    Dan Ebberts replied 12 years, 11 months ago 4 Members · 11 Replies
  • 11 Replies
  • Xinlai Ni

    December 1, 2009 at 4:44 pm

    Try this:
    timeToClimb = 1;
    timeToStay = 2;
    initialY = 243;
    positionY = initialY - 5 * Math.floor(time / (timeToClimb + timeToStay));
    t = time % (timeToClimb + timeToStay);
    [432, linear(t, 0, timeToClimb, positionY, positionY - 5)]

    Xinlai Ni
    Software Engineer, Google Inc.

  • Dan Ebberts

    December 1, 2009 at 4:50 pm

    It will be something like this:

    moveTime = .3;
    holdTime = 4.7;
    delta = [0,-5];

    seg = Math.floor(time/(moveTime+holdTime));
    t = time % (moveTime+holdTime);
    value + delta*seg + linear(t,holdTime,holdTime+moveTime,0,delta)

    Dan

  • Jonathan Reyes

    December 2, 2009 at 3:12 pm

    Thank you both! Works like a charm! If you have some time, could you explain what’s happening here? I know some basic expressions, but am by no means an expert (or even a novice for that matter) and I like to know how things work before i implement them in my projects. Also, using this method, is it possible to “ease” the animation of the position? thank you!!

  • Dan Ebberts

    December 2, 2009 at 8:41 pm

    Wherever you see “linear”, just change it to “ease”.

    I wish I had time to explain how it works, but I’m pretty jammed up this week.

    Dan

  • Jonathan Reyes

    December 2, 2010 at 8:56 pm

    Thanks again for this wonderful expression. However, I was wondering how I can apply to this to time. For example, I have a clip that I want to Time Remap where it plays for 1 second, pauses for 5 seconds, resumes play for 1 second, pauses for another 5 seconds, etc. It seems like this expression would work with some tweaks, unfortunately I’m not the best at this and can’t figure it out. any help would be appreciated, thanks!

  • Dan Ebberts

    December 2, 2010 at 9:08 pm

    Try this:

    moveTime = 1;
    holdTime = 5;

    seg = Math.floor(time/(moveTime+holdTime));
    t = Math.min(time % (moveTime+holdTime),moveTime);
    seg*moveTime + t

    Dan

  • Jonathan Reyes

    December 2, 2010 at 9:16 pm

    Thanks very much Dan! works perfectly!

  • Sebastian Heinrich

    May 29, 2013 at 6:19 pm

    Hi,
    I am quite a noob when it comes to expressions.
    Basically what I am trying to achieve is to connect your Expression (what perfectly does what I need) with an inertial Bounce.
    I want a layer to move in fixed intervals but also have a bounce at the end position. And I don’t want to use keyframes.
    I have been using the inertial Bounce Expression from Graymachine which is based on keyframes.
    But I am to stupid to find a way to connect these Expressions.
    Do you know how to do this?

    Thank you!

    So I want to connect this:

    timeToClimb = 1;
    timeToStay = 2;
    initialY = 243;
    positionY = initialY - 5 * Math.floor(time / (timeToClimb + timeToStay));
    t = time % (timeToClimb + timeToStay);
    [432, linear(t, 0, timeToClimb, positionY, positionY - 5)]

    with this:

    amp = .05;
    freq = 1.0;
    decay = 4.0;

    n = 0;
    if (numKeys > 0){
    n = nearestKey(time).index;
    if (key(n).time > time){
    n--;
    }}

    if (n == 0){ t = 0;
    }else{
    t = time - key(n).time;
    }

    if (n > 0){
    v = velocityAtTime(key(n).time - thisComp.frameDuration/10);
    value + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);
    }else{value}

  • Dan Ebberts

    May 29, 2013 at 9:10 pm

    I think this gives you the appropriate overshoot, but I don’t think you’re going to see much bounce with a velocity of 5 px/sec:


    timeToClimb = 1;
    timeToStay = 2;
    step = 5;
    initialY =243;
    positionY = initialY - step * Math.floor(time / (timeToClimb + timeToStay));
    t = time % (timeToClimb + timeToStay);

    freq = 1;
    decay = 2;

    if (t < timeToClimb){
    [432,linear( t, 0, timeToClimb, positionY, positionY - step)];
    }else{
    amp = step/timeToClimb;
    w = freq*Math.PI*2;
    [432,positionY - step] - [0,amp*(Math.sin((t-timeToClimb)*w)/Math.exp(decay*(t-timeToClimb))/w)];
    }

    Dan

  • Sebastian Heinrich

    May 29, 2013 at 9:38 pm

    Hi Dan,
    wow, that works perfectly.

    Yes, sure, those example values 5px/sec wouldn’t do it.

    I am creating a slideshow with hundreds polaroid images. This is so awesome coz it’s completely autmated now.

    I wish I was able to come up with such solutions. Would probably take me days. I can only partly understand the code. That’s really bugging me.

    Thank you so much.
    Sebastian

Page 1 of 2

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