Auto-orientation towards the camera is a 3D technique in After Effects with a lot of uses. Sometimes though, it would be better if the auto orientation only affected the layer's y axis. This is especially true if you want the layer to maintain its vertical orientation. In those cases you may want the object to turn and face the camera but to also maintain its perpendicular relationship with the ground plane.

If you examine the three movies to the right you can see the issue. The top movie shows a camera move where the vertical layers have no auto-orientation applied. It quickly becomes very obvious that the objects in the scene are paper-thin "cutouts".

In the middle movie, Auto-Orient Towards Camera has been applied to the bears and the tree. This certainly helps maintain the 3D illusion, but you can see that as the camera moves up, the characters' feet lose their connection point with the ground plane.

In the bottom movie, each layer has been constrained to orient itself towards the camera only on its y axis, maintaining contact with the ground plane.

So what we want to do here is conjure up an expression that will cause a layer to rotate on its y axis to face the camera, but doesn't affect the layer's x or z orientation.

It turns out that, using a little trigonometry, you can construct a fairly simple expression that will do the job.

The trick is to project the line that connects the layer's anchor point with the center of the camera, and then calculate the angle between that projection and the world x axis. Simple enough, right?

First we need to subtract the camera's position in world space from the layer's position in world space. This gives us a 3D vector connecting the center of the layer to the center of the camera. In case either the layer or the camera is a child of another layer, we'll use our old friend the toWorld() layer space transform to convert the layer's anchor point and the camera's center ([0, 0, 0]) to world coordinates before we do the subtraction. After we calculate the vector, it turns out that its x and z components are all we need to calculate the y rotation angle required to cause our layer to face the camera.

Here's the expression (apply it to the layer's y rotation property):


delta = toWorld(anchorPoint) - thisComp.activeCamera.toWorld([0,0,0]);
radiansToDegrees(Math.atan2(delta[0],delta[2]))

Without auto-orientation, the "cut out" nature of the characters is clearly visible.

With "Auto-Orient Towards Camera", a character's feet may lose contact with the ground.

By auto-orienting only on the y axis, foot contact is maintained.