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.
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%.
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);