Jump to content
Sign in to follow this  
KGB

Yet another expression question.

Recommended Posts

Ok, you can Mooo as much as you like. I came here for the fast, intelligent responce :-)

And I hate to bother you guys with what must be a VERY simple problem for some of yall but this is driving me batshit-crazy.

 

Here is what I am trying to do.

I have a layer, that is accelerating with respect to the y axis(emulating gravity, etc...).

When the y value of the layer is larger then the y value of another layer I want that acceleration(and movement to stop).

 

So I got this expression typed out.

 

if(thisComp.layer("Circle").position[1] < thisComp.layer("GroundPlane").position[1])

{[100, (position[1] * time * time * 12),3000];}

 

 

But its like the TEST is not happening!!! The thing keeps accelerating!!!! WTF?

Am I missing something simple? Cause its a pretty simple problem....

I used to do programing a long time ago, etc.... but am a noob with expressions(its the change over time that I havent grasped yet completely)

 

If you have the time, stop by, have a laugh at me, and give me a hint :D

Edited by KGB

Share this post


Link to post
Share on other sites

You're comparing the position[1] value without multiplying it by time*time. This value refers to the original y coordinate, which stays put, so your expression always evaluates TRUE. Try:

 

yaccel = thisComp.layer("Circle").position[1]*time*time*12;

ystop = thisComp.layer("GroundPlane").position[1]

 

if (yaccel < ystop)

[100, yaccel, 3000]

else

[100,ystop, 3000]

 

(Warning - I'm not in front of AE right now so can't test this, but I think this should work better. It's also better to have an else part to explicity say what happens if the condition is NOT satisfied).

Edited by Spritely

Share this post


Link to post
Share on other sites

Don't forget the brackets:

 

if (yaccel < ystop){

[100, yaccel, 3000]

}else{

[100,ystop, 3000]

}

 

The curly brackets are really only necessary if you are performing more than one operation in a block. However, it tends to be good coding style to include them or when you are first starting out. I would also recommend to include them.

Share this post


Link to post
Share on other sites

Ok!, that worked as intended, but just to understand the code if you can please explain the difference.

 

The way I saw my code originally:

 

if(thisComp.layer("Circle").position[1] < thisComp.layer("GroundPlane").position[1])

{[100, (position[1] * time * time * 12),3000];}

 

I was comparing the CURRENT value of position[1], or y. The way I saw it, I didnt need to multiply in my if statement, because I would have multiplied and thus increased that value in the previous frames(like a for loop for example)

 

In a test Text layer, the test condition DID work as intended.

 

For example, I put this in the source text field

 

if(thisComp.layer("Circle").position[1] < thisComp.layer("GroundPlane").position[1])

1

else

0

 

 

Was I somehow not reading the current value of position or something? Very puzziling.

Share this post


Link to post
Share on other sites

Ok!, that worked as intended, but just to understand the code if you can please explain the difference.

 

The way I saw my code originally:

 

if(thisComp.layer("Circle").position[1] < thisComp.layer("GroundPlane").position[1])

{[100, (position[1] * time * time * 12),3000];}

 

I was comparing the CURRENT value of position[1], or y. The way I saw it, I didnt need to multiply in my if statement, because I would have multiplied and thus increased that value in the previous frames(like a for loop for example)

 

In a test Text layer, the test condition DID work as intended.

 

For example, I put this in the source text field

 

if(thisComp.layer("Circle").position[1] < thisComp.layer("GroundPlane").position[1])

1

else

0

Was I somehow not reading the current value of position or something? Very puzziling.

 

 

Because you are reading the current value BEFORE your expression (position[1] * time * time * 12) so you are not getting the actual real value. That's why you need to include you expression in your conditional

 

-lloyd

Share this post


Link to post
Share on other sites

oh ok...thanx man

That explains it. I thought that that code was run every frame, and that the Position value would return the position of the layer at the current time(which was multiplied in the frames before current frame)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...