Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Change rate of movement between two points

  • Change rate of movement between two points

    Posted by Mike Foran on October 10, 2024 at 7:33 pm

    Sorry if this has been asked before in some form but I can’t find an answer. I’m looking to dynamically determine and set variables for the beginning and end position of an object, and then use an expression to move that object at a rate I determine. So p1=[x1,y1], and p2=[x2,y2] and then I would like to move the object in a line between those two points at a certain rate. Thanks.

    Brie Clayton replied 5 months ago 3 Members · 8 Replies
  • 8 Replies
  • Dan Ebberts

    October 10, 2024 at 7:50 pm

    This is a pretty general solution that should work OK. You can tie variable spd to a slider (as long as you don’t animate the slider):

    p1 = [100,100];
    p2 = [500,500];
    spd = 100; // pixels per second
    tStart = inPoint;
    v = normalize(p2 - p1);
    t = Math.max(time-tStart,0);
    d = Math.min(spd*t, length(p1,p2));
    p1 + v*d;
  • Mike Foran

    October 10, 2024 at 9:47 pm

    Somehow I knew you’d have a solution to this one Dan. Works a charm! Many thanks!

  • Brie Clayton

    October 11, 2024 at 1:04 am

    Thank you for solving this, Dan!

  • Mike Foran

    October 11, 2024 at 4:43 am

    Woah it’s been a while since I’ve posted a question in here. Are these coins a way of paying folks who volunteer solutions?

  • Mike Foran

    October 11, 2024 at 2:35 pm

    Dan, I always enjoy breaking down your solutions because I learn something new every time. What I’d like to do here that I can’t seem to figure is to make this movement loop. I’m thinking that it would be modifying the tStart variable so that, instead if being set to inPoint, it would instead be reset at certain time increments. I’m just not sure how to get there. Ideally, the loop would reset on the frame BEFORE it reached the position in P2 (the shape being moved in this case has repeaters to form a grid, so I’m trying to seamlessly move this grid from one instance to the next on a loop, so it seems like it is endlessly moving). I’d appreciate your guidance.

  • Dan Ebberts

    October 11, 2024 at 3:54 pm

    If it needs to loop, I think I’d approach it a little differently:

    p1 = [100,100];
    p2 = [500,500];
    spd = 100; // pixels per second
    tTot = length(p1,p2)/spd;
    tStart = inPoint;
    t = Math.max((time-tStart)%tTot,0);
    linear(t,0,tTot,p1,p2)
  • Mike Foran

    October 11, 2024 at 4:34 pm

    Ah interesting! Well that is working great as well. Thanks again for your invaluable assistance.

  • Brie Clayton

    October 11, 2024 at 6:18 pm

    Hello Mike,

    Yes! COW coins reward the overall participation in Creative COW itself, forum coins and badges highlight a person’s niche knowledge, and solve coins underscore how very helpful folks like Dan Ebberts are.

    Right now we are paying in recognition, but toward the end of this month we will be holding a raffle that links back to coinage in specific forums with RE:Vision Effects plug-ins!

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