ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# Camera to affect a layer's Gaussian Blur and Opacity

FAQ   •   VIEW ALL
 Camera to affect a layer's Gaussian Blur and Opacity on Nov 21, 2017 at 8:20:43 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!

 Re: Camera to affect a layer's Gaussian Blur and Opacityon Nov 22, 2017 at 2:54:36 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 &lt;= 60 ){ onBlur = blurAmount; } else { onBlur = 0; } onBlur```

For Expression Tutorials:

 Re: Camera to affect a layer's Gaussian Blur and Opacityon Nov 22, 2017 at 8:22:56 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?

 Re: Camera to affect a layer's Gaussian Blur and Opacityon Nov 22, 2017 at 9:43:00 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: