Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Reveal object upon movement

  • Reveal object upon movement

    Posted by Derek Bass on October 2, 2012 at 1:30 am

    Hi everyone –

    I have about 100 small objects in my composition that begin moving at different times. Each object needs to be transparent, or not visible in whatever way possible, until it starts moving.

    I don’t have a lot of experience with expressions, but my best guess is that there is some kind of on/off switch, if/else expression that could be made for opacity of each object so that opacity is 0% while the object is stationary, but 100% if it is moving. The other factor is that I want each object to stay visible indefinitely after it becomes visible.

    Yes, I realize that I could just start each layer when each object is moving, but it would help this particular composition to stay organized and give me more mobility if I could use an expression.

    Does anyone know an expression that could do the job?

    Derek Bass replied 13 years, 11 months ago 2 Members · 7 Replies
  • 7 Replies
  • Dan Ebberts

    October 2, 2012 at 2:57 am

    If the layer keeps moving once it starts, it should be a pretty simple opacity expression like this:

    if (Math.abs(transform.position.speed) > 0) 100 else 0

    If the layer eventually stops and you still want it to be visible, that’s a bit more complicated.

    Dan

  • Dan Ebberts

    October 2, 2012 at 3:12 am

    Here’s the more complicated version:


    t = time;
    val = 0;
    while (t >= inPoint){
    if (Math.abs(transform.position.speedAtTime(t)) > 0){
    val = 100;
    break;
    }
    t -= thisComp.frameDuration;
    }
    val

    Dan

  • Derek Bass

    October 2, 2012 at 6:48 pm

    Thanks, Dan! The objects do stop and then need to stay visible, so thanks for the more complicated expression.

    I don’t think this will work for me, though. It worked at first, but when I apply it to all my 100+ layers, AE times out, gives me an error message, and disables the expressions.

    I’m using a pretty hefty computer, but I think all the expressions overload my processor. To complicate things, I didn’t mention before that each layer already has an indexed expression, w/slider, to follow the previous layer in space and time, and it already takes a while to process:


    x=thisComp.layer(index+1).content("Shape 1").transform.position[0]+ thisComp.layer("slider - first row distance").effect("Distance - firstRow")("Slider");
    y=thisComp.layer(index+1).content("Shape 1").transform.position.valueAtTime(time-thisComp.layer("slider - metascan color bars").effect("Metascan bar control")("Slider")*.005)[1];
    [x,y]

    I think I’m overusing expressions in this composition. Do you think that trying to add the transparency expression on top of the other expression is a lost cause? In any case, the expressions you sent will help me a lot in the future because I’ve needed something like this more than once before, so many thanks for that.

  • Dan Ebberts

    October 2, 2012 at 8:59 pm

    Using a cascading expression (like your position expression) on 100 layers will probably bog things down. On each frame, the expression would have to execute over 5,000 times. And your expression actually accesses the next layer twice, so you’re looking at over 10,000 expression executions for each frame. You’d be much better off doing your calculations based on each layer’s index (and possibly a single “leader” layer) rather than having each layer refer to the next layer. That could give you a 100 to 1 performance improvement right there.

    Dan

  • Derek Bass

    October 2, 2012 at 9:39 pm

    Thanks – that makes sense. For position, x value is stationary for each layer, so I can find a solution for that. It’s the y value that moves and needs to relate to the object before and after. Currently, this is what I have:

    y=thisComp.layer(index+1).content("Shape 1").transform.position.valueAtTime(time-thisComp.layer("slider - metascan color bars").effect("Metascan bar control")("Slider")*.005)[1];

    I might still need to add some objects into the chain between others, so I want to make the expressions universal, so I wouldn’t have to go back and change each layer if, e.g., it changes from 98th to 99th from the leader. How would I use index witout cascading?

  • Dan Ebberts

    October 2, 2012 at 10:27 pm

    I haven’t tested this, but I think it would be something like this:

    s = thisComp.layer(“slider – metascan color bars”).effect(“Metascan bar control”)(“Slider”);
    L = thisComp.layer(“leader”);
    delay = (L.index – index)*s*.005;
    y = L.content(“Shape 1”).transform.position.valueAtTime(time – delay)[1]

    Dan

  • Derek Bass

    October 3, 2012 at 7:12 pm

    This worked great. Being able to use these expressions adds so much to this composition, and I can’t thank you enough. Problem solved!

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