ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# distance from camera?

FAQ   •   VIEW ALL
 distance from camera? by Joe Moleon Mar 14, 2011 at 10:09:37 pm

How do you figure out the distance of a 3d layer from the camera? I'm using the depth of field so I'd like to know what to set my focus to to focus on things as the camera moves...

 Re: distance from camera?on Mar 15, 2011 at 5:23:33 am

Turn ON depth of field for your camera to enable.
View your comp in the TOP view.
select the camera and you should see a plane for the focal point.
(scrub "Focal Distance" value and you can see which plane this is)

 Re: distance from camera?on Mar 15, 2011 at 1:14:08 pm

You could also use the length expression to find the distance, but Tom's answer is less complicated.

- The Great Szalam
(The 'Great' stands for 'Not So Great, in fact, Extremely Humble')

No trees were harmed in the creation of this message, but several thousand electrons were mildly inconvenienced.

 Re: distance from camera?on Mar 15, 2011 at 8:28:04 pm

[Michael Szalapski] "You could also use the length expression to find the distance, but Tom's answer is less complicated."

Also, while this gives you an accurate distance to the camera, it doesn't work well for setting the focus distance.

I was going to try and explain why here, but it's been done before so I'll just link to Dan's site :)

http://motionscript.com/design-guide/auto-focus.html

Darby Edelen

 Re: distance from camera?on Mar 16, 2011 at 4:16:06 am

A layer is in perfect focus if its position minus the camera's position is equal to the Focus Distance value.

The formula reads as such -
LayerPos-CameraPos=FocusDistance

You can take advantage of this formula to ensure that a layer is in focus by linking the camera's Focus Distance to a layer's position regardless of where the layer is positioned (static or animating).

For example, say you have a layer, let's call it HeroLayer, that you always want to be in focus. You would apply the following Expression to the Focus Distance property.

//Start Script
LayerPosZ = thisComp.layer("heroLayer").transform.position[2];
CameraPosZ = transform.position[2];
LayerPosZ-CameraPosZ
//End Script

Now if you move either the camera or the heroLayer, the layer will always be in focus. You can also create a Null Layer that will allow you to easily change the 'perfect focus' from one layer onto another.

HTH
RoRK

AE Training in South East Asia. AE templates for sale and rental. Click here for more