Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Loop AE expression?

  • Loop AE expression?

    Posted by Patrik Fröhler on June 1, 2015 at 8:08 pm

    Hi, I’m trying to loop the z-position of a 3D layer using only expression, I need it to work without using keyframes or time remapping, but I’m running in to a strange problem.

    This is the code I’m testing with,

    This loops one time (code1):
    var_zpos = time*2000;
    if (var_zpos > 5000){var_zpos = var_zpos-5000};

    [640, 360, var_zpos];

    And If I do this it loops 7 times (code2):
    (this is the result I want but forever looping)
    var_zpos = time*2000;
    if (var_zpos > 5000){var_zpos = var_zpos-5000};
    if (var_zpos > 5000){var_zpos = var_zpos-5000};
    if (var_zpos > 5000){var_zpos = var_zpos-5000};
    if (var_zpos > 5000){var_zpos = var_zpos-5000};
    if (var_zpos > 5000){var_zpos = var_zpos-5000};
    if (var_zpos > 5000){var_zpos = var_zpos-5000};
    if (var_zpos > 5000){var_zpos = var_zpos-5000};

    [640, 360, var_zpos];

    unexpected result. (code3):
    var_zpos = time*2000;
    if (var_zpos > 5000){var_zpos = var_zpos-5000};
    if (var_zpos > 10000){var_zpos = var_zpos-10000};
    if (var_zpos > 15000){var_zpos = var_zpos-15000};
    if (var_zpos > 20000){var_zpos = var_zpos-20000};
    if (var_zpos > 25000){var_zpos = var_zpos-25000};
    if (var_zpos > 30000){var_zpos = var_zpos-30000};
    if (var_zpos > 35000){var_zpos = var_zpos-35000};

    [640, 360, var_zpos];

    To me this don’t makes sense, that the “if statement” only runs once then I have to paste another one. I understand why this first code would not work, and It behaves as I would expect, when time*2000 is 10000 it will be 10000-5000 and It will just continue past the 5000 position, but then I would expect this (code 3) to behave like (code2)currently does:

    simple test comp download(CS6):
    https://patan77.com/download/ae_loop_z_test.aep

    thanks.

    Darby Edelen replied 11 years, 3 months ago 2 Members · 1 Reply
  • 1 Reply
  • Darby Edelen

    June 1, 2015 at 8:27 pm

    It’s not entirely clear what specific behavior you’re after that lead you to approach the problem the way you did, so I apologize if this isn’t helpful, but I’d recommend using a modulus operator to loop instead:


    loop_value = 5000;
    zpos = (time*2000) % loop_value;

    value + [0,0,zpos]

    Darby Edelen

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