Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions When If Else Condition met Value should not change suddendly-Should change in defined time duration

  • When If Else Condition met Value should not change suddendly-Should change in defined time duration

    Posted by Sameer Patel on August 20, 2020 at 4:20 pm

    Hi Folks,
    I am working on an after effects project. Where I have 5 shape layer. I have indexed these shape layer positions as per the attached slider counter number value.
    Here is expression code of one layer attached with “v” slider:
    v=thisComp.layer("Null 2").effect("v")("Slider");
    w=thisComp.layer("Null 2").effect("w")("Slider");
    x=thisComp.layer("Null 2").effect("x")("Slider");
    y=thisComp.layer("Null 2").effect("y")("Slider");
    z=thisComp.layer("Null 2").effect("z")("Slider");
    var arr = [x,y,z,v,w];
    arr.sort(function(a, b){return b - a});
    t=15;
    var r =arr.indexOf(v);
    if ( r >= 0 && r<1) {
    295.9059;
    } else if ( r >= 1 && r<2) {
    503.9059;
    } else if (r >= 2 && r<3) {
    711.9059;
    } else if (r >= 3 && r<4) {
    919.9059;
    } else if (r >= 4 && r<5) {
    1127.9059;

    } else {
    value;
    }

    When the above condition met for example: if ( r >= 0 && r<1) position will be {
    295.9059;
    . I want to achieve that when any condtion met such as in this example then position value should not change suddenly. It will go from Previus position to next position (after fullfilment of if else condition (for eg 295.9059;)) in defined time such as one second of duration.
    Please help;
    Sorry for my bad English;

    Carl Ranger

    Sameer Patel replied 5 years, 12 months ago 3 Members · 7 Replies
  • 7 Replies
  • Scott Mcgee

    August 21, 2020 at 8:43 am

    your issue is that you’ve not stated the animation.

    So if you want it to animate you’d need to put in a transition expression.

    if ( r >= 0 && r<1) {
    295.9059;
    }

    What you want is to add ease() or linear()

    ease(Time,StartTime,EndTime,StartPosition,EndPosition);

  • Sameer Patel

    August 21, 2020 at 11:28 am

    Sir Thanks for Your reply.
    I have already tried the Interpolation method. it is not working because slider value is changing over time and because of that position rank (index) also changing.

    Here is the expression code, I have tried;
    if ( r >= 0 && r<1) {
    beginCount = transform.yPosition.valueAtTime(time-1.1);
    endCount = 295.9059;
    stopTime = (time-1.1)+0.5;
    startTime=(time-1.1);
    t = time;
    s = linear (t, startTime, stopTime, beginCount, endCount);

    I have tried Another varient of linear() expression;
    if ( r >= 0 && r<1) {
    beginCount = transform.yPosition.valueAtTime(time-1.1);
    endCount = 295.9059;
    dur = 0.5;

    t = time-inPoint;
    s = linear (t, 0, dur, beginCount, endCount);

    But unfortunately, the result is the same i.e. position value directly jump from the previous one to output(for eg 295.9059).

    Here is the screenshot of my project method1:
    Method1

    Method2;

    My problem will solve if we can get the timestamp of , When condition met i.e. if ( r >= 0 && r<1).

    I can achieve this with the help of a marker but want a complete automated expression method.

    Regards

    Carl Ranger

  • Scott Mcgee

    August 21, 2020 at 2:19 pm

    Found this for you that might offer the answer you seek

    https://www.youtube.com/watch?v=Nn4biGJScsU

    Some contents or functionalities here are not available due to your cookie preferences!

    This happens because the functionality/content marked as “Google Youtube” uses cookies that you choosed to keep disabled. In order to view this content or use this functionality, please enable cookies: click here to open your cookie preferences.

  • Scott Mcgee

    August 21, 2020 at 2:24 pm

    Ignore me, just watched it and it’s manually done.

    However Tomas who’s a regular boffin on here created this. Which is what you’re after. Or can guide you better.

    https://www.youtube.com/watch?v=A3_0aAVegc8

    Some contents or functionalities here are not available due to your cookie preferences!

    This happens because the functionality/content marked as “Google Youtube” uses cookies that you choosed to keep disabled. In order to view this content or use this functionality, please enable cookies: click here to open your cookie preferences.

  • Filip Vandueren

    August 21, 2020 at 6:57 pm

    AFAIK, he hasn’t shared his precise method yet, and it is scripting based so I think it just creates “manual” keyframes as well.

  • Filip Vandueren

    August 21, 2020 at 7:00 pm

    Hi Carl, it is not something that expressions can do easily.
    You will have to check the order not just now, but at different times and interpolate or average between them manually.

  • Sameer Patel

    August 22, 2020 at 6:46 pm

    Hi Experts,

    I gon through the video attached by Scott and several other videos on youtube but unfortunately, don’t find the solution in these videos.

    As Filip said that “It is not easy to achieve this task with the only expressions” that why I have changed my approach and I came to very close to the required result with the combination of expressions (easeOut()…..) and Marker.

    But the problem is that the expression is only working(Here Position value Interpolating From 711.9059 to 919.9059 in the duration of 0.5 second as per my requirement.) at First Marker (index 0) on the layer and at the second Marker (index 1) on the same layer, Interpolation method expression “easeOut()” is not working and yPosition value Jumping directly From 919.9059 to 711.9059 in a single frame. What is the solution at the second marker so that It should also interpolate the same as at the first Marker.

    I have attached The Project File Here, please go through it. It will be very helpful in understanding the problem.
    https://1drv.ms/u/s!AqasXseMlvyPnFWVtHkVyb2xWCfG?e=sN8CSc

    Here is the Expression applied on Yellow Solid Layer yPosition;

    YELLOW=thisComp.layer("SLIDER CONTROL").effect("YELLOW")("Slider");
    BLACK=thisComp.layer("SLIDER CONTROL").effect("BLACK")("Slider");
    var arr = [YELLOW,BLACK];
    arr.sort(function(a, b){return b - a});
    var r =arr.indexOf(YELLOW);

    m = thisLayer.marker;
    i = m.nearestKey(time).index;

    if (m.nearestKey(time).time > time)
    { i--;
    }
    if (i < 1) { i = 1;
    }
    else{i;
    }

    timeAtMarker_i=thisComp.layer("Yellow").marker.key(i).time;
    startPoint=thisComp.layer("Yellow").marker.key(i).time;
    endPoint=startPoint+0.5;
    beginCount=thisComp.layer("Yellow").transform.yPosition.valueAtTime(timeAtMarker_i);
    t=time;

    if ( r >= 0 && r<1) {
    yPosition = easeOut(t, startPoint, endPoint, beginCount, 711.9059);

    } else if ( r >= 1 && r<2) {
    yPosition = easeOut(t, startPoint, endPoint, beginCount, 919.9059);

    } else {
    value;
    }

    I am very thankful to you guys. Please help me, I’m not very good at expression.
    Here is a screenshot too.

    Regards

    Carl Ranger

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