ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Loop AE expression?

COW Forums : Adobe After Effects

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Patrik FröhlerLoop AE expression?
by on Jun 1, 2015 at 8:08:25 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):
http://patan77.com/download/ae_loop_z_test.aep

thanks.


Return to posts index


Darby EdelenRe: Loop AE expression?
by on Jun 1, 2015 at 8:27:32 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


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]