Do you really mean “x amount of time”, or do you mean its opacity needs to be 100% until it reaches a certain distance from the camera and then it fades until it reaches some other distance where it would be 0%? That would be like this:
C = thisComp.activeCamera;
startFade = 500;
endFade = 1500;
d = length(toWorld(anchorPoint),C.toWorld([0,0,0]));
linear(d,startFade,endFade,100,0)
I’m not sure what it would be if you mean something else.
Dan