Activity › Forums › Adobe After Effects Expressions › start moving when reaching CONDITION if
-
start moving when reaching CONDITION if
Posted by Toni Pa on May 13, 2014 at 9:18 pmHi
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;}
Dan Ebberts replied 12 years, 3 months ago 2 Members · 6 Replies -
6 Replies
-
Dan Ebberts
May 13, 2014 at 10:22 pmYou 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
-
Toni Pa
May 14, 2014 at 8:44 amups 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] zv=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;
} -
Dan Ebberts
May 14, 2014 at 4:30 pmI’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
-
Toni Pa
May 14, 2014 at 6:48 pmOk 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! -
Dan Ebberts
May 14, 2014 at 6:59 pmIn 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
Reply to this Discussion! Login or Sign Up