How to Use lookAt in After Effects for 3D Layers

The lookAt function in Adobe After Effects is a built-in expression method designed to automatically calculate the orientation or rotation required for a 3D layer to face another point in 3D space. This guide explains what the lookAt function is, breaks down its core syntax, and provides a direct, step-by-step process for pointing any 3D layer or camera directly at a target layer.

What is the lookAt Function?

In After Effects, lookAt is a vector math function that eliminates the need to manually keyframe rotation when tracking an object. It accepts two 3D coordinates—an observer position and a target position—and outputs a three-value array [x, y, z] representing the exact rotation angles needed for the observer to face the target.

Syntax

lookAt(fromPoint, atPoint)
  • fromPoint: The starting coordinate in 3D space, typically the position of the layer you are rotating.
  • atPoint: The destination coordinate in 3D space, typically the position of the target object.

How to Orient a 3D Layer Toward a Target

Step 1: Prepare Your Layers

  1. Create or import the layer you want to rotate (e.g., an arrow, text, light, or camera).
  2. Create your target layer (e.g., a Null Object or Shape Layer) and name it "Target".
  3. Enable the 3D Layer switch (the cube icon) for both layers in the timeline.

Step 2: Apply the Expression to Orientation

  1. Select the layer you want to point toward the target.
  2. Press R to reveal its rotation and orientation properties.
  3. Hold Alt (Windows) or Option (macOS) and click the stopwatch next to Orientation.

Step 3: Insert the Code

For simple setups where neither layer is parented, use this expression:

targetPos = thisComp.layer("Target").transform.position;
lookAt(transform.position, targetPos);

Handling Parented Layers with World Space Coordinates

If either layer is parented to another object, local position coordinates will cause alignment errors. To fix this, convert the coordinates to world space using toWorld:

targetLayer = thisComp.layer("Target");
targetPos = targetLayer.toWorld(targetLayer.anchorPoint);
currentPos = toWorld(anchorPoint);

lookAt(currentPos, targetPos);

Correcting Default Layer Axis Offsets

After Effects layers point along their positive Z-axis by default when lookAt is applied.

  • If your layer's graphic is facing along the X-axis or Y-axis, it may appear sideways or backwards.
  • To correct this without altering the expression, adjust the layer's native rotation using the individual X, Y, or Z Rotation properties, which operate independently on top of the Orientation values.
  • Alternatively, add mathematical degree offsets directly within the expression array.