Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions keeping things relative

  • keeping things relative

    Posted by Bert Brown on June 5, 2008 at 9:04 pm

    I want an object’s opacity to go continuously from 50 to 100 and back down to 50 as it moves from the right to the left. so when it hits its exact middle it’ll be 100 opacity, 50 at its start and end.

    the problem is the start and ending position keyframes might need to be adjusted without breaking into the expression.

    how would i go about this, or at the very least, how do I get information from keyframes?

    ———————————-

    peep my over-the-interweb band, red abbott.
    “we electro-rock over long distances…”

    Filip Vandueren replied 17 years, 11 months ago 2 Members · 3 Replies
  • 3 Replies
  • Filip Vandueren

    June 5, 2008 at 11:07 pm

    you could use this:

    <code>
    if (position.numKeys>1) {
    t1=position.key(1).time;
    t2=position.key(2).time;
    mid=(t1+t2)/2;
    o= time<mid ? linear(time,t1,mid,50,100) : linear(time,mid,t2,100,50);
    } else {
    value;
    }
    </code>

    that uses the timedifference rather than the value difference between the two keyframes to do the tween.
    So the tweening will only happen between the two specified keyframes 1 and 2.

    To use the X-values to do the tweening in your example could be something like this:

    <code>
    if (position.numKeys>1) {
    x1=position.key(1).value[0];
    x2=position.key(2).value[0];
    mid=(x1+x2)/2;

    // interpolation methods only work if the first value is smaller than the second,
    // so we need to order them:
    left=Math.min(x1,x2);
    right=Math.max(x1,x2);

    x= position[0];
    o=x<mid ? linear(x,left,mid,50,100) : linear(x,mid,right,100,50);
    } else {
    value;
    }
    </code>

    if you’re copy-pasting from your E-mail change the &lt; into lesser-than signs and the &gt; in to greater than signs

  • Bert Brown

    June 6, 2008 at 2:32 pm

    thanks, this is really helpful, especially being shown the “position.key(1).value[0]” part.

    just a quick thing, are those question marks supposed to be in the code? if so, what does that do, i’ve never seen it before in expressions.

    ———————————-

    peep my over-the-interweb band, red abbott.
    “we electro-rock over long distances…”

  • Filip Vandueren

    June 7, 2008 at 1:23 pm

    Hi Bert,

    it’s a shorthand for “if then else” when assigning a value:

    a= b<10 ? 100 : -100;

    is shorthand for:

    if(b<10){
    a=100;
    }
    else {
    a=-100;
    }

    so:

    a = condition ? value if true : value if false

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