Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Objects moving on different paths and keeping the same speed. (?)

  • Objects moving on different paths and keeping the same speed. (?)

    Posted by Themystical on March 22, 2007 at 3:46 pm

    Hi, I’m new using AE7 and after whatching every tutorial on the creativecow website I got a pretty good hand at it, however I’m having a tiny (probably common) problem matching the speed of two or more objects moving on different paths. I alreadi posted this question to the basic forum but as suggested I think expression is the way to go.
    Anyway, here’s a simple animated gif to show you the problem.

    https://img407.imageshack.us/img407/4172/timingzo4.gif

    See? the left dot is moving on a straight path and an horizontal line moves with it, the right dot wont match the other’s speed ending up missing the horizontal line intersection.

    Basically the path on the left has been copied on the right and the bezier point in the middle streched a bit to form a S shape.
    The 2 black dots start at the same time and end at the same time but in between…how do I make both dots to travel at the same speed?

    Any help greatly appreciated.

    Thanks

    TheMystical

    Themystical replied 19 years, 5 months ago 3 Members · 4 Replies
  • 4 Replies
  • Filip Vandueren

    March 22, 2007 at 4:19 pm

    Do you want them to travel at the same speed, or have them be on the same Y position:

    If the latter, you actually want the right dot to slow down and speed up a lot…
    If they were travelling at the same speed, the left one would arrive much earlier; because it has a shorter route.

    Not so easy, this one… I’l think about it.

  • Darby Edelen

    March 22, 2007 at 5:59 pm

    Well, the easiest way to cheat this is to have the dot on the right use it’s own X coordinate for position and steal the Y coordinate from the dot on the left. If you put the layer of the dot on the left directly above the layer with the dot on the right then this expression would work:

    tempX = transform.position[0]; //use this layers X position
    tempY = thisComp.layer(index-1).transform.position[1]; //use the Y position of the layer above this layer
    [tempX, tempY]

    Note that the dot on the right will not be following it’s path precisely anymore. I guess that’s the price you pay =)

    As noted in the previous response the dots are traveling paths of different lengths, so if they traveled at the same speed the dot with the shorter route (on the left) would arrive first.

  • Filip Vandueren

    March 22, 2007 at 11:12 pm

    Apply this expression to the position of your curved path layer:
    Change the first line to mention the layer that travels down the straight line.
    Change the precision on 2nd line to a higher value if you’re not satisfied


    followLayer=thisComp.layer("straight");
    precision=3;

    flag=true;
    t=0;
    if (position.numKeys) {
    while (flag) {
    if (position.valueAtTime(t)[1]>=followLayer.position[1] || t>position.key(numKeys).time) {
    flag=false;
    } else {
    t=t+thisComp.frameDuration/precision;
    }
    }

    position.valueAtTime(t)

    } else { value; }

    This forces the curved layer to find a point in time on it’s path that has the same Y-value (position[1]) as the straight line (followLayer) has now.
    The precision defines show many time per frame it should check, once per frame (precision=1) is probably not accurate enough, so use a value between 3 and 10, that should suffice depending on the speed.

    Caveat:
    Because of this checking algorithm, the curved line cannot double back on itself, ie. follow a path that is so curved that at some point it travels back up.
    The expression will skip this section.

  • Themystical

    March 22, 2007 at 11:42 pm

    That’s awesome, it works great, really thank you. 🙂

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy