5 years later, but could be appreciate by other people :
// Start of Script
d = length(toWorld(anchorPoint),thisComp.activeCamera.position);
if (d>1400){
minDist = 2000;
maxDist = 1400;
maxOpacity = 100;
minOpacity = 0;
linear(d,minDist,maxDist,maxOpacity,minOpacity)
}else{
minDist = 600;
maxDist = 1400;
maxOpacity = 0;
minOpacity = 100;
linear(d,minDist,maxDist,maxOpacity,minOpacity)
};
// End of Script
You have to put it on the “opacity” of the object