You don’t need if statement to do this, the thing you need is this expression of the position of the layer:
xyPos = toComp(thisLayer.position); // project this layer to comp plane
distToCompCenter = length(xyPos – [thisComp.width / 2, thisComp.height / 2]; // how far this layer is to the comp center
distToCameraZ = 10 * distTocompCenter; // how far this layer to the camera in Z direction is 10 times of how far it is to the comp center
[thisLayer.position[0], thisLayer.position[1], thisComp.layer(“Camera”).position[2] + distToCameraZ] // modify this layer’s Z position relative to the camera.
This is assuming camera is looking at the Z+ direction, if not, you may want to offset the layer along the “look at” direction of the camera.
Xinlai Ni
Software Engineer, Google Inc.