why doesn't this work?

Moderators: Disciple, zlovatt

Post Reply
vfxg08
Posts: 9
Joined: April 10th, 2011, 1:57 pm

I am really just starting out with expressions or rather trying to understand vs. just copying them. I want to know why this doesn't work.


w = wiggle(2,400);
if (time > 2){
ease(time,[640,400],[640,200]);
}else{
x =640;
y =400;
}

[x,y]
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

What are you trying to do, exactly?

There are a lot of problems with your expression. For example: The wiggle is not used at all. Your ease should look more like this:

ease(time,2,outPoint,[640,400],[640,200])

The ease isn't compatible with the last statement ([x,y]) be cause ease generates an array directly and x and y aren't defined when time > 2 seconds.

Dan
vfxg08
Posts: 9
Joined: April 10th, 2011, 1:57 pm

Thanks for the reply! Well what I originally wanted to have happen was as my X position changed I wanted it start wiggling only on X or y(as I would ultimately define it) at a certain point then go back to its regular course of animation. So what I'd hoped was that by writing:

Original Idea:
w = wiggle(2,45);
x = value[0];
y= value[1];

if ( x > 200 && x < 500){
w[1]
}else{
value[1]
}
[x,y]

Nothing happened when I typed the above expression. That's when I went to the second expression as an attempt to trouble shoot, but that didn't work out either.

w = wiggle(2,400);
if (time > 2){
ease(time,[640,400],[640,200]);
}else{
x =640;
y =400;
}

[x,y]


The concept is the same though. I'm trying to achieve this: if an object is animating across the screen when it reaches certain point on x or y do something(wiggle, change direction,etc)

Thanks again for the help!
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

I think this is closer to your original idea:

Code: Select all

w = wiggle(2,45);
x = value[0];
if ( x > 200 && x < 500){
 [x,w[1]] 
}else{
 value
}
Dan
vfxg08
Posts: 9
Joined: April 10th, 2011, 1:57 pm

thanks that worked great!

I have a question concerning the expression. why is that I should use [x, w[1]]. Is this because wiggle requires me to define both properties in the array? also I attempted to take the above expression a step "further", yea... anyway here what I tried, but the result was a little unexpected because the y position jumps to the top of the screen before the Math.sin function works:

w = Math.sin(time*4)*25;
x = value[0];
y = value[1];
if ( x > 200 && x < 500){
[x,w+[1]]
}else{
value
}

Thanks again for all the help!
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

wiggle generates an array, so if you only want 1 dimension wiggled, you split it out (as w[1] for y, in this case).

Try this:

Code: Select all

w = Math.sin(time*4)*25;
x = value[0];

if ( x > 200 && x < 500){
 value + [0,w]
}else{
  value
}

Dan
vfxg08
Posts: 9
Joined: April 10th, 2011, 1:57 pm

thanks major help! Ok, with the value + [0,w], I'm a little lost as to what I'm actually saying here.... Am I saying that position[x,y] + [0,y]... meaning that I'm adding noting to [x] and adding the variable to y? At least that's what I think is going on. I'm working with all of this now trying to put my own creative juices to work. So I'm extremely thankful for helping understand how work with expressions in this sense!

One final thing before I go back to hammering the nail with my wacky ideas for expressions:

say I wanted to say

x = value[0];
y = value[1];
w = wiggle(2,200);

if(time > 1 && time < 3){
ease(time,1,3,[457,366],[1040,366])
if( time >3 && time < 5){
[x,w[1]]
}else{
value
}
}else{
value
}

This one I tried to go all out. I didn't get an error but nothings happening. of course this happened when I tried to go for the second if statement so what am I doing wrong?! I want to be an if statement master(expressions in general!) also I think if someone could point out some limitations with if statements. For instance can I have an infinite amount of if's? Like in my above attempt can I keep going? Thanks again!
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

>meaning that I'm adding noting to [x] and adding the variable to y?

Yes - that's it.

I think your latest expression should look more like this:

Code: Select all

x = value[0];
w = wiggle(2,200);

if(time > 1 && time < 3){
ease(time,1,3,[457,366],[1040,366])
}else if( time >3 && time < 5){
  [x,w[1]]
}else{
  value
}
Dan
vfxg08
Posts: 9
Joined: April 10th, 2011, 1:57 pm

thanks Again for all of your help Dan!
OK that expression certainly worked but "else if".... definitely a new one for me.

Also with ease controlling the animation I was hoping that when I moved into the second part of the expression
the wiggle would pick-up/use the existing position. Instead it starts at the initial position. Thinking about it, I understand why that happened. Would this be the place to use the while statement?
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

>Would this be the place to use the while statement?

I can't think of any way that would help you.

There are a number of options. One would be to isolate the wiggle like this:

Code: Select all

x = value[0];
w = wiggle(2,200) - value;

if(time > 1 && time < 3){
  ease(time,1,3,[457,366],[1040,366])
}else if( time >= 3 && time < 5){
  [1040,366] + [0,w[1]]
}else{
  value
}

Dan
vfxg08
Posts: 9
Joined: April 10th, 2011, 1:57 pm

Great! That's what I was trying to achieve!
Thanks a ton! Time to get to work!
Post Reply