Expression to access the layer above in After Effects

/**
* The following expression will allow you to access the layer above
* See the examples below for how to use it in practice
*/
thisComp.layer(index-1);

Example usage:

/**
* Access the position of the layer above:
**/
thisComp.layer(index-1).position;

More advanced examples:

Offset the position of a layer based on the layer above it (2D)

Note: For this example, you will first need to do the following:

  1. Add a slider control to your bottom layer
  2. Rename the slider control X Offset
  3. Duplicate the slider control
  4. Rename the duplicated slider control Y Offset
var x_offset = effect("X Offset")("Slider");
var y_offset = effect("Y Offset ")("Slider");
var layer_above = thisComp.layer(index-1);
var x_pos = layer_above.position[0] + x_offset;
var y_pos = layer_above.position[1] + y_offset;
[x_pos, y_pos];

Offset the position of a layer based on the layer above it (3D)

Note: For this example, you will first need to do the following:

  1. Add a slider control to your bottom layer
  2. Rename the slider control X Offset
  3. Duplicate the slider control
  4. Rename the duplicated slider control Y Offset
  5. Duplicate the slider control again
  6. Rename the duplicated slider control Z Offset
var x_offset = effect("X Offset")("Slider");
var y_offset = effect("Y Offset")("Slider");
var z_offset = effect("Z Offset")("Slider");
var layer_above = thisComp.layer(index-1);
var x_pos = layer_above.position[0] + x_offset;
var y_pos = layer_above.position[1] + y_offset;
var z_pos = layer_above.position[2] + z_offset;
[x_pos, y_pos, z_pos];