FORUMS: list search recent posts

start moving when reaching CONDITION if

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Toni Perelló
start moving when reaching CONDITION if
on May 13, 2014 at 9:18:20 pm

Hi
Im trying to start de movement in Y direction when I reach a condition but I need to sustract the time value at that point so there is not a jump at the moment of start de movement.
Any thoughts?
Thanks in advance :)

px=transform.xPosition;
if (px>300) {
transform.yPosition.valueAtTime(time)+time*10;
} else {
transform.yPosition;}


Return to posts index

Dan Ebberts
Re: start moving when reaching CONDITION if
on May 13, 2014 at 10:22:40 pm

You need to add a loop to find out how long x has been greater than 300. Something like this:


px=transform.xPosition;
if (px>300) {
t = time;
while (transform.xPosition.valueAtTime(t) > 300){
t -= thisComp.frameDuration;
}
transform.yPosition.valueAtTime(t)+(time-t)*10;
} else {
transform.yPosition;
}



Dan



Return to posts index

Toni Perelló
Re: start moving when reaching CONDITION if
on May 14, 2014 at 7:52:27 am

Thank you for your fast answer!
Works perfect :)


Return to posts index


Toni Perelló
Re: start moving when reaching CONDITION if
on May 14, 2014 at 8:44:05 am

ups I may have talk to fast...
It works perfect for the example i posted but in my real project I'm tracking the position of a child object and when I tried to adapt the code I got an error caused for an infinite loop.
I also tried:
while ((P[2]>800)&&(P[2]>900))
but it didnt work...
Any idea to solve this?

* I will explain the scene: I got a group of objects (trees houses...) as child of a road (solid 90º rotation) which moves back into the horizon. When I reach the horizon ( z position= 800) I want the objects move down to be hidden into the ground.

Thank you all for your time

L=thisLayer;
P=L.toWorld(L.anchorPoint); //position of the child P[0] x, P[1] y, P[2] z

v=30; //velocity

if (P[2]>800) {
t = time;
while (P[2]>800) {
t-=thisComp.frameDuration;
}
transform.zPosition.valueAtTime(time-t)*v; // the z.position is actually y position because the parent has 90º rotation...
} else {
transform.zPosition;
}


Return to posts index

Dan Ebberts
Re: start moving when reaching CONDITION if
on May 14, 2014 at 4:30:09 pm

I'm not clear on why you have this set up the way you do, but your loop will be infinite because within the loop, you don't update the value of P based on the new value of t, so P[2] will never be less than 800.

Dan



Return to posts index

Toni Perelló
Re: start moving when reaching CONDITION if
on May 14, 2014 at 6:48:12 pm

Ok I get it, but why the first example works well? if the x.position will be always geting bigger... because im moving the layer to the right
Anyway I think I would try a different approach, without parenting.
Thank you!


Return to posts index


Dan Ebberts
Re: start moving when reaching CONDITION if
on May 14, 2014 at 6:59:44 pm

In the first example, every time through the loop (in the while statement itself), you are retrieving the position value from one frame prior to the previous time through the loop (by using the newly calculated time value of t). Eventually you find a time where the value is not greater than 800.

Because expressions have no memory of previous calculations, every frame, you have to go back in time until you find that frame where the threshold was reached.

Dan



Return to posts index

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