Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Throw expression, but only for a set distance

  • Throw expression, but only for a set distance

    Posted by Navarro Parker on June 19, 2013 at 12:11 am

    I have to set up a ton of little tiny squares that move 10 pixels up in a semi-random order.

    Right now I’m using two position keyframes… which works. But it’s kind of a hassle to make sure both keyframes are selected if I need to reposition them around the screen.

    I ran into this “Throw” expression that moves a layer in one direction (left) into infinity.

    // Throw (move at a constant speed without keyframes)
    veloc = -10; //horizontal velocity (pixels per second)
    x = position[0] + (time – inPoint) *veloc;
    y = position[1];
    [x,y]

    Is there a way to make it stop moving after a certain pixel distance? So I can place a square anywhere and it’ll move 10 pixels up beginning at its inPoint without any keyframes?

    EDIT: on second look, this expression doesn’t seem to work either. Syntax error in line 3?

    Navarro Parker replied 11 years, 7 months ago 2 Members · 8 Replies
  • 8 Replies
  • Dan Ebberts

    June 19, 2013 at 12:28 am

    Some variation of this, probably:

    veloc = -10;
    maxPixels = 10;
    x = position[0] + Math.max((time – inPoint)*veloc, -maxPixels);
    y = position[1];
    [x,y]

    Dan

  • Navarro Parker

    June 19, 2013 at 12:33 am

    Fantastic (as always). Thank you Dan!!

    PS: Check your email

  • Navarro Parker

    June 19, 2013 at 9:34 pm

    Hey Dan!

    I’m using this today and I’m getting unreliable results. Sometimes the layer doesn’t move at all, and sometimes it infinitely moves, and sometimes it works perfectly.

    In this case, I’m using veloc = 100 to move it up and veloc = -100 to move it down — which I think is the cause of the trouble… maybe?

    veloc = -100;
    maxPixels = 15;
    x = position[0];
    y = position[1] + Math.max((time – inPoint) * veloc, -maxPixels);
    [x,y]

  • Dan Ebberts

    June 19, 2013 at 10:10 pm

    This should work the way you’re using it (negative velocity to move down, positive to move up):

    veloc = -100;
    maxPixels = 15;
    y = Math.min(maxPixels,(time – inPoint) * Math.abs(veloc)) * (veloc < 0 ? 1 : -1);
    value + [0,y]

    Dan

  • Dan Ebberts

    June 19, 2013 at 10:14 pm

    I think this is a little cleaner:

    veloc = -100;
    maxPixels = 15;
    y = clamp((time – inPoint)*veloc,-maxPixels,maxPixels);
    value – [0,y]

    Dan

  • Navarro Parker

    January 22, 2015 at 12:38 am

    Hey Dan, I dusted off this expression and I’m getting a syntax error at line 3

    // Throw (move at a constant speed without keyframes)
    veloc = -10; //horizontal velocity (pixels per second)
    x = position[0] + (time – inPoint) *veloc;
    y = position[1];
    [x,y]

    Has something changed in CC (2013)?

    EDIT: I’m applying this to a Point Control effect.

  • Dan Ebberts

    January 22, 2015 at 12:48 am

    >Has something changed in CC (2013)?

    Nothing that would effect that expression. Somehow you got the minus operator (-) replaced with a long dash. Just replace line 3 with this, and you should be good to go:

    x = position[0] + (time – inPoint)*veloc;

    Dan

  • Navarro Parker

    January 22, 2015 at 1:46 am

    Wow, good eyes!

    Must be Google Docs doing some sneaky en dash substitution.

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