Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions linking opacity to rotation

  • linking opacity to rotation

    Posted by Criis Daw on September 22, 2011 at 7:21 pm

    Hi can anyone help me with this please.

    I would like to link the opacity of a layer to its rotation…… but

    i would like it to be over a specific range . Something along the lines of ‘if the angle of this layer is between 100 and 120 degrees then the layer will have a transparency between 0-100 , where the angle 100 opacity = 0 and at 120 opacity = 0 and the mid point the angles, 110, the opacity = 100’

    (would be easy is expressions understood english !)

    Also i would like it to work after full revolutions also So the opacity peaks at 0x110 1×110 2×110 .

    Thanks for your help

    Chris

    Adrien Tasic replied 12 years, 3 months ago 3 Members · 10 Replies
  • 10 Replies
  • Dan Ebberts

    September 22, 2011 at 7:33 pm

    This should work:


    angle = transform.rotation%360;
    minAngle = 100;
    maxAngle = 120;
    mid = (maxAngle+minAngle)/2;
    if (angle < mid)
    linear(angle,minAngle,mid,0,100)
    else
    linear(angle,mid,maxAngle,100,0)

    Dan

  • Criis Daw

    September 22, 2011 at 8:20 pm

    i love
    DAN EBBERTS

    thanks very much !

  • Criis Daw

    September 22, 2011 at 8:27 pm

    Sorry…

    i didnt explain properly before. I need the transparancy to be linked to the y rotation value.

    sticking a ‘y’ in there doesnt seem to help

  • Dan Ebberts

    September 22, 2011 at 8:32 pm


    angle = transform.yRotation%360;
    minAngle = 100;
    maxAngle = 120;
    mid = (maxAngle+minAngle)/2;
    if (angle < mid)
    linear(angle,minAngle,mid,0,100)
    else
    linear(angle,mid,maxAngle,100,0)

  • Criis Daw

    September 22, 2011 at 9:00 pm

    Doh !

    I am not usally such a dunce but i have a terrible hangover

    thanks again.

  • Adrien Tasic

    February 11, 2014 at 10:53 am

    Hello Dan,
    thank you for the script, as well as your whole website.

    Maybe can someone here help me with my script, in the same spirit of this one?

    I’m trying to use this code but then my layer stays transparent, it may have a mistake:
    angle = transform.yRotation%360;
    minAngle = -23;
    maxAngle = 22;
    if ([angle < minAngle] || [angle > maxAngle]) 0 else 100

    There I want the opacity to go from 0 to 100 without fading. Hope this is understandable enough, or?
    Thank you for the help.

    Ad

  • Dan Ebberts

    February 11, 2014 at 2:21 pm

    In the last line, try changing [ and ] to ( and ).

    Dan

  • Adrien Tasic

    February 13, 2014 at 10:07 am

    Hello Dan,
    thank you for the answer! Yes I finally found that later on, actually I’m hitting on another problem…
    After I linked this layers expressions to a Null in my main composition
    this way :
    angle = comp("MainComp").layer("Null1").transform.yRotation%360;
    minAngle = -11,25;
    maxAngle = 11,25;
    if (angle < minAngle || angle > maxAngle) 0 else 100

    I’m trying to find a way so that this Null1 stays automatically perpendicular to its path. Something like Auto-orient, but this one doesn’t change my Null rotation (so doesn’t effect on my layers expression..)
    Hope I made it clear, and thank you so much for the help.

    Adrien

  • Dan Ebberts

    February 13, 2014 at 6:02 pm

    2D? If so, try this for the null’s rotation:

    v = transform.position.velocity;
    radiansToDegrees(Math.atan2(v[1],v[0]))

    Dan

  • Adrien Tasic

    February 14, 2014 at 11:18 am

    Hello Dan, thanks again!
    Yes your expression actually works well ! I just changed the y and x coordinates in it to x and z :…(v[0],v[2])

    Only a little problem with the z axis of my Null facing the back (like starting à 180°) when adding the expression to it.

    Thanks really much for your clarification on this ! Love it, it’s pretty close from the ‘Auto-orient Y Only’ in your Expressioneer’s Design Guide, but with transform.position.velocity.
    This rocks, 🙂

    Adrien

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