Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Camera to affect a layer’s Gaussian Blur and Opacity

  • Camera to affect a layer’s Gaussian Blur and Opacity

    Posted by Nadya Sastrawinata on November 21, 2017 at 8:20 pm

    Hey guys,
    I’m having an issue with creating an expression for a camera to be able to affect a certain layer to activate gaussian blur and opacity when it’s about 50-60 pixels away. I thought of defining the difference of distance of the camera on z and the layer itself as a variable, then making an if conditional for this variable. The camera will be animated, but if it’s just 60 pixels away from each other then the if conditional will work. I tried to put it into words but if anyone can help me out, please do!

    Basically;
    variable = distance of camera on z – distance of layer on z
    if variable = 60, activate gaussian blur and opacity,
    else no gaussian blur and opacity

    Thank you!

    Nadya

    Demarc Johnson replied 8 years, 5 months ago 2 Members · 3 Replies
  • 3 Replies
  • Demarc Johnson

    November 22, 2017 at 2:54 am

    You have to you use the && sign to do this conditional. When you use the && sign then both side of the condition must be true in order to run the first block of code or the else block of code will be ran.

    var cameraPosZ = thisComp.layer("Camera 1").transform.position[2]; //Change this by pick whipping the your camera's z position
    var z = transform.position[2] - cameraPosZ;
    var blurAmount = 30; //Change this to the amount of blur you want
    var onBlur;
    if( z >= 50 && z <= 60 ){
    onBlur = blurAmount;
    } else {
    onBlur = 0;
    }
    onBlur

    For Expression Tutorials:
    https://www.youtube.com/channel/UCe77szX2n1WSKsGs-2gmbDw

  • Nadya Sastrawinata

    November 22, 2017 at 8:22 pm

    Hey DeMarc,
    Thanks for helping out! I tried your code but it gave me an “error at line 5 in property ‘Opacity’ of layer 11 (brown) in comp maincomp. Expected: )., expression was disabled”. I asked a friend of mine and he came up with the same kind of code and had the same kind of issue. Could you help me out?

    Nadya

  • Demarc Johnson

    November 22, 2017 at 9:43 pm

    Sorry, when I pasted the code creative cow’s forum changed it. In line 5 paste this:
    if( z >= 50 && z <= 60 ){

    For Expression Tutorials:
    https://www.youtube.com/channel/UCe77szX2n1WSKsGs-2gmbDw

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