Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Move from position to position by x and then y

  • Move from position to position by x and then y

    Posted by Peter Menich on January 5, 2015 at 5:46 pm

    Hey All,

    I’m trying to cook an expression where a layer will move around the comp to a number of keyframed positions, but rather than move ‘as the crow flies’ it moves first in the x dimension and then the y.

    I’ve been looking at the ‘nearestKey’ command and ‘.key’, but I can’t quite figure it out.

    I thought maybe you could treat each move as a right angled triangle, where the direct move is the hypotenuse and then you could use trig to figure out the x and y… but again, my brain has failed me.

    It doesn’t help that it’s my first day back after christmas either!

    Any pointers will be greatly appreciated.

    P

    Peter Menich replied 11 years, 4 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    January 5, 2015 at 6:25 pm

    Try this:


    v = value;
    if (numKeys > 0){
    n = nearestKey(time).index;
    if (key(n).time > time) n--;
    if ((n > 0) && (n < numKeys)){
    t = time - key(n).time;
    dt = key(n+1).time-key(n).time;
    if (t < dt/2){
    v = linear(t,0,dt/2,key(n).value,[key(n+1).value[0],key(n).value[1]]);
    }else{
    v = linear(t,dt/2,dt,[key(n+1).value[0],key(n).value[1]],key(n+1).value);
    }
    }
    }
    v

    Dan

  • Peter Menich

    January 5, 2015 at 7:45 pm

    Dan, You nailed it again!

    Awesome.

    Many thanks.

    Pete

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