Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions If and And and Then!!

  • If and And and Then!!

    Posted by Jim Lefevre on October 10, 2011 at 9:53 am

    I’m sure you’ll appreciate that doing a search for ‘if’ ‘and’ and ‘then’ brings up pretty much every post so I’m starting a new post here. Apologies if this has been posted before!

    I have 94 coloured circles arranged across a frame in a logo.

    I’m trying to do a clever expression which flips the circles around around when an object (CHANGER) passes over them in an almost mexican-wave type effect.

    I am having a fair amount of success but I also need each CIRCLE to stay at 0 degrees before it passes over and stop at 180 degrees once the CHANGER has passed.

    I am ‘hiding’ them using that nice Dan Ebebrts expression that hides the layer if it’s not facing the camera and so I am revealing them through rotation.

    I can ‘reveal’ them (by revolving to camera as the CHANGER passes over them) fine however I need them to stop revolving after the CHANGER has done it’s stuff and passed them as, at the moment they continue to revolve as the CHANGER is carrying on it’s transform to effect the other layers further along the composition

    Ok, so I’m using an if/else command to say…

    if CHANGER is before the object’s position THEN hide it (i.e. keep it flipped round away from camera)

    …but how do I find that sweet spot after that which stops the expression once it’s passed a certain value. I feel I need an AND bit.

    Or do I?

    hmmm…

    Any help would be appreciated and am more than happy to elaborate on the above it it’s too confusing (it’s confusing enough for me and I kNOW what’s going on!!)

    many thanks

    jim

    // APPLIED TO MY CIRCLES'S x ROTATION;

    xn = thisComp.layer("CHANGER").transform.position[0];
    yn = thisComp.layer("CHANGER").transform.position[1];

    if ((my_rot=(transform.position[0]-xn)) > 0){my_rot=181}else {my_rot=(180-(transform.position[0]-xn))};

    transform.xRotation=my_rot

    //APPLIED TO OPACITY (just fyi);

    a = toWorldVec([0,0,1]);
    b = thisComp.layer("Camera 1").position - toWorld(anchor_point);
    c = dot(a,b)/length(b);
    if (c > 0) 0 else 100

    http://www.jimlefevre.com

    Jim Lefevre replied 14 years, 7 months ago 3 Members · 6 Replies
  • 6 Replies
  • Dan Ebberts

    October 10, 2011 at 5:44 pm

    I think some variation of this will work for x rotation:

    xn = thisComp.layer(“CHANGER”).transform.position[0];
    range = 100;
    ease(transform.position[0],xn-range,xn+range,0,180)

    Dan

  • Darby Edelen

    October 10, 2011 at 5:55 pm

    if ((my_rot=(transform.position[0]-xn)) > 0){my_rot=181}else {my_rot=(180-(transform.position[0]-xn))};

    An if/then statement isn’t the best thing to use in this case. Instead try using the “linear()” function.

    my_rot = transform.position[0] - xn;
    linear(my_rot, 0, -500, 181, 0);

    Also you don’t need the last statement “transform.xRotation = my_rot”. Your full code should work as:


    xn = thisComp.layer("CHANGER").transform.position[0];

    my_rot = transform.position[0] - xn;
    linear(my_rot, -500, 0, 0, 181);

    As “my_rot”, which holds the difference in x-position between the current layer and the CHANGER null, ranges from -500 to 0 the result of the expression will range from 0 (facing the camera) to 181 (away from the camera). Any value greater than 0, when CHANGER is on the right side of the layer, will return 181 and any value less than -500, when CHANGER is on the left side, will return 0. If you want the rotation to happen faster then you can make the 3rd argument to linear a smaller number (-100 instead of -500 for example).

    The linear() function is awesome, I suggest you read up on it 🙂

    Darby Edelen

  • Darby Edelen

    October 10, 2011 at 5:56 pm

    [Dan Ebberts] “xn = thisComp.layer(“CHANGER”).transform.position[0];
    range = 100;
    ease(transform.position[0],xn-range,xn+range,0,180)”

    Wow. I’ve never thought to have the range animate in a linear() function. This is why you get paid the big bucks Dan 🙂

    Darby Edelen

  • Jim Lefevre

    October 11, 2011 at 1:00 pm

    Wowzers, right, I think I’m glimpsing some light through there.

    That linear function is new to me and I suspect (when I get my head around it) an awesome bit of ammunition to store. I noticed you going through it with someone else a while back (https://forums.creativecow.net/thread/227/9696).

    As soon as my latest render finishes I’m going to spark this up and see how it works.

    In fact I’ve just properly read/re-read your final bit on tightening it all up and my goodness me, that’s just fantastic. It’s so great how the more one journeys into expressions the tighter and tighter ones phrasing becomes!!

    Many many thanks Dan and Derby. Awesome stuff!

    (will post any success in a bit)

    http://www.jimlefevre.com

  • Jim Lefevre

    October 13, 2011 at 9:55 am

    I popped Dan’s expression in to start with as I suddenly needed to get a render out and it works spectacularly.

    I’m assuming that the ease(x,x,x,x) expression works in a similar way to the linear (x,x,x,x) and I’m going to start playing with Darby’s as that looks a little simpler for me to understand the linear expression.

    One thing I’m now trying to do (and this is as much about the basics of expressions) is to apply a similar set-up but to scale which has three values it needs returning (it’s in a 3D space). How would that set-up that’s applied to a single value (the x rotation) be applied to one that has needs three values returning but apply it only to the x-scale?

    I’m aware that AE needs to end up with an array of something like [x,y,z].

    I’ve tried to drop the code in there

    x= linear(my_rot, -500, 0, 0, 181)

    but obviously there’s something wrong here…

    head aching but getting closer!!!

    http://www.jimlefevre.com

  • Jim Lefevre

    October 13, 2011 at 10:24 am

    ahhhhhh… a bit of thinking and I’m taking my own grown up steps forward…

    realising I eventually need

    [x,y,z]

    I’ve got Dan’s expression onto a ‘slider’ in each of the layers and am referring it back to that so with the slider with Dan’s expression but having the range as 0 – 100 …

    x=100-(effect(“Slider Control”)(“Slider”)*80);
    y=(effect(“Slider Control”)(“Slider”));
    z=transform.scale[2];
    [x,y,z]

    I’m getting there!!!

    I’m sure this is a bit clunky but I feel a tiny bit proud of myself!!!

    jim

    http://www.jimlefevre.com

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