Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Reading distance from object

  • Reading distance from object

    Posted by Hiski Suomela on February 5, 2018 at 2:49 pm

    Hey everyone!

    I have a problem. I’m having an expression to read distance between two layers and changing the opacity of other of the layers with an ease.

    My problem is that the distance is between the anchorpoints of the objects. I need somehow the “position” of the master layer to be the actual shape of that layer, not the anchorpoint position. I mean as I move the master layer, it changes the opacity around it, not only around it’s anchorpoint.

    Is this even possible or do I have to give up with this? Hope you guys can help. ☺

    – Hiski

    master = thisComp.layer("haka1");
    beginOp = [0];
    endOp = [100];
    beginDistance = 300;
    endDistance = 10;
    distance = length(this.position, master.position);
    ease(distance, beginDistance, endDistance, beginOp, endOp)

    Hiski Suomela replied 8 years, 7 months ago 2 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    February 6, 2018 at 12:52 am

    Try this:


    master = thisComp.layer("haka1");
    r = master.sourceRectAtTime(time,false);
    p = master.toComp([r.left+r.width/2,r.top+r.height/2]);
    beginOp = 0;
    endOp = 100;
    beginDistance = 300;
    endDistance = 10;
    distance = length(position, p);
    ease(distance, endDistance, beginDistance, endOp, beginOp)

    Dan

  • Hiski Suomela

    February 6, 2018 at 7:06 am

    Hi, Dan! Thanks for your reply!

    The code seems to act like the one I pasted here. The opacity still reacts to the anchorpoint of “haka1” but not the shape.

    Some more info. I’m having a 4K 16:9 composition and the master layer I’m moving is a shape of ^. I’d like to have small squares (like big pixels) to change opacity depending on how close they are to that shape path. That means I also want the code to ignore the bounding box. Only to affect the shape of the layer.

    Did I do something wrong?

  • Hiski Suomela

    February 6, 2018 at 7:13 am

    EDIT:

    Sorry. It doesn’t affect depending on the position of the anchorpoint but still the position of the very center of “haka1”.

    So yeah, I’d need it to affect to the borders of the shape if that’s even possible. 🙂

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