## Expression with if/else for position

Scripting for After Effects

### Expression with if/else for position

Hi,

I have a problem with ifs and elses in AE.
I want to create a moving object with different equations of movement as a function of time. How can I create something like

if(time<100) -> y-value=function1, x-value=const.
if(time>=100 && time<200) -> y-value=function2, x-value = const.
else -> function3...
?

Thx for help
jumpnrun

Posts: 2
Joined: 07/24/2015, 4:49 am
System Specs: Windows 8.1 64bit, I7 4770k, 16GB RAM, AMD R9 290

### Re: Expression with if/else for position

Ok, I found out myself, it's:

if(time<xy){[x-position,function1]} else if(time>=xy && time<ab){[x-position,function2]} else {[x-position,function3]};

But I have another problem:

It works basically, but if I use this expression, the position just stays the same after 9s. I have no idea why.

Expression:

In a 1920*1080 comp with 60fps, for the position of a solid layer. I created a random circle mask, thats why there is x=1000 etc. just so I can see it ^^.

if(time<=3){[1000,((1/2*10*time*time))*10]} else {[1000,-(-30+(2.5*(-9.8)+24.5)/1.884)*(2.5/1.884)*(1-Math.pow(Math.E,(-1.884*(time-3)/2.5))-(2.5*(-9.8)+24.5)*(time-3)/1.884)+(1/2*10*9*10)]};

A lot of numbers I know.
I guess it has something to do with the exponential-function. But no idea how to fix that.

The movement after 3s should look like this:

http://www.wolframalpha.com/input/?i=pl ... rom+0+to+6

Edit:

if I change Math.pow(Math.E,blabla) to 2.718^blabla it does something after 9s but the movement has a very low resolution. The position does huge jumps.

Edit2:

Live leraning process - I'm so dumb. Wrong starting speed and of course it doesn't move if both forces a equal...
jumpnrun

Posts: 2
Joined: 07/24/2015, 4:49 am
System Specs: Windows 8.1 64bit, I7 4770k, 16GB RAM, AMD R9 290