AfterEffects

Example: Match camera’s focal plane to another layer

  Apply the following expression to a camera layer’s Focus Distance property to have its focus distance match the distance to the anchor point of a layer named “target”:
  target = thisComp.layer("target");
  V1 = target.toWorld(target.anchorPoint) - toWorld([0,0,0]);
  V2 = toWorldVec([0,0,1]);
  dot(V1,V2);