Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Varying Opacity of a Layer based on proximity of another…

  • Varying Opacity of a Layer based on proximity of another…

    Posted by Mark Woloschuk on February 16, 2007 at 12:28 am

    Seems like this would be simple but it’s over my head expression-wise. I want to vary the opacity of a layer such that opacity increases as another control layer approaches it and then decreases it as it moves away. I’m guessing that it would also be a good idea to tie the falloff radius to a slider on the control layer too.

    Any thoughts? I’m guessing this would be useful for a lot of cool things.

    Thanks,

    Mark Woloschuk

    Mark Woloschuk replied 19 years, 2 months ago 2 Members · 2 Replies
  • 2 Replies
  • Mike Clasby

    February 16, 2007 at 1:11 am

    Ok, this is from an old post by Filip Vandueren, it goes on Opacity. When you move the layer closer to the layer “Control” it’s opacity is controlled by the expression.

    min_distance=100; // closer than this, opacity will be 100%
    max_distance=10000; // from this distance, opacity will be 0%

    n=this_comp.layer(“Control”); // name of your controlling layer
    d=length(to_world(anchor_point), n.to_world(anchor_point));

    ease(d, min_distance, max_distance, 100, 0)

    If you want the falloff to be linear instead of ease, you can also change the last line to:

    linear(d, min_distance, max_distance, 100, 0)

    If you add sliders (Effect>Expression Controls>Slider Control) to the layer with the opacity expression and name them, “Slider Control min” and “Slider Control max”, and pickwhip to the values you get:

    min_distance=effect(“Slider Control min”)(“Slider”); // closer than this, opacity will be 100%
    max_distance=effect(“Slider Control max”)(“Slider”); // from this distance, opacity will be 0%

    n=this_comp.layer(“Control”); // name of your controlling layer
    d=length(to_world(anchor_point), n.to_world(anchor_point));

    ease(d, min_distance, max_distance, 100, 0)

  • Mark Woloschuk

    February 27, 2007 at 7:47 am

    Thanks Mike,

    For some reason I never got an email letting me know you responded. We were doing a mockup of an art installation for a grant proposal and time was short so I ended up handing this task off to a flash person but I like your solution better.

    Thanks again – I know it will come in handy for many things.

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