Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Changing Position keyframes but keeping the speed graph

  • Changing Position keyframes but keeping the speed graph

    Posted by Mackie John on September 6, 2022 at 8:10 am

    I want to change the keyframe value of the position property if a certain condition is met

    x = [100,200]; // my new keyframe1 value

    y = [200, 300]; // my new keyframe2 value

    If (n==1) // if true change the position keyframe1 and keyframe2

    {

    v1 = valueAtTime(key(1).time);

    v2 = valueAtTime(key(2).time);

    linear(time,key(1).time,key(2).time,x,y);

    }

    else value

    This works for me but the above doesnt respect the speed graph. I have a speed graph set on the position, but when i run using the above expression the speed graph is ignored. Its runs in a linear fashion. How do i use both the expression as above and the speed graph.

    Mackie John replied 3 years, 7 months ago 3 Members · 4 Replies
  • 4 Replies
  • Andrei Popa

    September 6, 2022 at 5:04 pm

    I think this will only work correctly if the value of key 2 is bigger than the value of key 1

    x = [100, 200]; // my new keyframe1 value
    y = [200, 300]; // my new keyframe2 value
    if(n == 1) // if true change the position keyframe1 and keyframe2
    {
    v1 = valueAtTime(key(1).time);
    v2 = valueAtTime(key(2).time);
    linear(value[0], v1[0], v2[0], x, y);
    }
    else value
  • Dan Ebberts

    September 7, 2022 at 6:31 am

    It’s a little tricky, but I think this will work in most situations:

    newV1 = [100,200];
    newV2 = [200,300];
    if (numKeys > 1){
    v1 = key(1).value;
    v2 = key(numKeys).value;
    t1 = key(1).time;
    t2 = key(numKeys).time;
    if (time < t1){
    newV1;
    }else if (time > t2){
    newV2;
    }else{
    delta = v2 - v1;
    newDelta = newV2 - newV1;
    if (Math.abs(delta[0]) < .001){
    x = v1[0];
    }else{
    x = newV1[0] + ((value[0] - v1[0])/delta[0])*(newDelta[0]);
    }
    if (Math.abs(delta[1]) < .001){
    y = v1[1];
    }else{
    y = newV1[1] + ((value[1] - v1[1])/delta[1])*(newDelta[1]);
    }
    [x,y];
    }
    }else
    value
  • Mackie John

    September 7, 2022 at 6:35 am

    This surely works thank you.

  • Mackie John

    September 7, 2022 at 2:56 pm

    This also works. Im grateful for the response

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