ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

FAQ   •   VIEW ALL
 Linking opacity to rotation on Sep 28, 2017 at 2:28:05 pm

I have the following expression (adapted from this thread) on an opacity parameter, linking the rotation of a null to the opacity, so it fades in and out when the null approaches a specific angle (a).

This does precisely what I want, but has two problems.

1. If a = 0, and the null animates from 0x+315.0° to 1x+0.0° (or from 0x-315.0° to -1x+0.0°), the opacity will remain at 0 until the revolution has been completed, and only then pops into 100%.

2. If the rotation of Null 1 is negative, it treats a as if it's a positive integer. So for instance, if rotation is 0x-270.0, the object where a=270 will be at 100% opacity (instead of a=90, like would make sense)

How can I address these two issues? I've tried a lot of different Math.abses and modulos, but I can't figure it out.

```var a = 45; var r = Math.abs((thisComp.layer("Null 1").transform.zRotation)%360); var d = Math.abs(a-r); ease(d, 10,36, 100,0);```

 Re: Linking opacity to rotationon Sep 28, 2017 at 5:24:52 pm

Try this:

a = 45;
r = thisComp.layer("Null 1").transform.zRotation;
d = (r - a)%360;
if (d > 180) d -= 360;
if (d < -180) d += 360;
ease(Math.abs(d), 10,36, 100,0);

Dan

 Re: Linking opacity to rotationon Sep 29, 2017 at 8:38:52 am

Brilliant! Thank you so much, that's just the job!

 Re: Linking opacity to rotationon Jan 17, 2019 at 10:21:26 pm

Hi Dan

Forgive my greenness, but what do each of the numbers in the final line correspond to...?

ease(Math.abs(d), 10,36, 100,0);

I'm guessing the 100 and 0 are the opacity, but I could be wrong...10 and 36, are they a radial value...?

I grabbed this expression to make lights go on and off around a 'wheel of fortune' as it spins, so they keep time with the wheel as it slows down. The wheel has 56 distinct points (odd number, I know, but that's what's in the artwork I'm obliged to follow) where I'm placing the lights, making for an annoying spacing of every 6.4 degrees (rounded down). Adjusting the a value makes them go off when the wheel hits the correct angle, I've figured that much out. I'd like to narrow the angle range so they go on and off faster, and I it seems to me adjusting these numbers would do it. Would you mind explaining it to me?

Thanks

Pete Burges

 Re: Linking opacity to rotationon Jan 17, 2019 at 10:39:46 pm

The 100 and 0 are the opacity. The 10 and 36 are rotation values in degrees. So that expression will fade out as the rotation value moves away (in either direction) from the target value (45). The fade begins at 10 degrees from the target and ends at 36 degrees.

Dan