Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Attach lens flare to a layers anchor point

  • Attach lens flare to a layers anchor point

    Posted by Espen Jakobsen on January 27, 2009 at 3:05 pm

    I’ve used one of the videocopilot turorials to make my 2d lens flare center follow a 3d layers’ position , but my problem is that the lens flare stays on the layers’ top left, but I need it to be in the layers’ center:

    https://espenja.com/mov/lens.mov

    The layer it follows is obviously the sun. I tried to via expressions make the sun layers’ anchor point be the same as the position and then link the lens flare center to the sun layers’ anchor point, but then the sun stopped moving. I’m sure this is an easy problem to solve, but I just cant see how myself.

    Darby Edelen replied 17 years, 3 months ago 3 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    January 27, 2009 at 3:47 pm

    What’s the expression you’re using now?

    Dan

  • Espen Jakobsen

    January 27, 2009 at 8:13 pm

    thisComp.layer(“sun”).toComp([0,0,0]);

    Used this to link the lens flare center to the sun layers’ position

  • Dan Ebberts

    January 27, 2009 at 8:55 pm

    This should put it in the center of the sun layer:

    L = thisComp.layer(“sun”);
    L.toComp([L.width/2,L.height/2]);

    If you haven’t moved the anchor point, this should work as well:

    L = thisComp.layer(“sun”);
    L.toComp(L.anchorPoint);

    Dan

  • Espen Jakobsen

    January 27, 2009 at 9:31 pm

    Ah! So dividing the position coordinates by two will put it in the center, thanks a million! 🙂

  • Darby Edelen

    January 28, 2009 at 6:22 pm

    [Espen Jakobsen] “Ah! So dividing the position coordinates by two will put it in the center, thanks a million! :)”

    Just to clarify, Dan isn’t dividing any position coordinates by two. If I rewrite this it may make more sense:


    L = thisComp.layer("sun");
    center = [L.width/2, L.height/2];
    L.toComp(center);

    The above expression is the same as what Dan gave you, only I’ve created a new variable to hold the layer coordinates we’re providing to toComp().

    The function toComp() is expecting a coordinate in layer space, in this case specifically it wants a coordinate in the layer space of the layer L (the “sun” layer).

    In your original code you had:

    thisComp.layer("sun").toComp([0,0,0]);

    Which would return the location of the point [0,0,0] on the layer (the upper left corner) in composition coordinates. What Dan did is instead gave the toComp() function a coordinate representing the center of the layer.

    In order to find the center of the layer he simply divided the width and height of the layer in pixels by 2:

    [L.width/2, L.height/2]

    Does that make sense? If, instead, he had written:

    [L.width, L.height]

    Then the flare would have followed the lower right corner of the “sun” layer. What we’re doing here is taking a point in layer space (like a layer’s anchor point) and converting it to composition space (like a layer’s position coordinates).

    Darby Edelen

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