Let's suppose we just need a simple proximity detector. We want to cause a layer to change colors when another layer comes within a certain distance. This doesn't need to be as precise as a collision detector, where we would want to know if any visible pixels of two layers overlap.

What we need to do here is create a loop that will examine each of the other currently active layers with video content and see if any of them is close enough to trigger the proximity condition. In this case we'll just have the layer change color when it is close to another layer. We'll do this by crafting our expression for the Color parameter of a Fill effect.

In this case, if we use round shapes, our setup will approximate a collision detector because we will use the distance between two layers as the proximity condition. This turns out to be half the sum of the two layer widths.

Note that for efficiency, we will want to break out of the loop as soon as we find one layer that meets the proximity condition.

out = [1, 1, 0, 1];
for (i = 1; i <= thisComp.numLayers; i++){
  if (i == index) continue;
  L = thisComp.layer(i);
  if (! (L.active && L.hasVideo)) continue;
  delta = (width + L.width)/2;
  if (length(position, L.position) <= delta){
    out = [1, 0.25, 0, 1];

Layers turn from yellow to red when they come in contact with another layer.

Remember that in expressions, colors are represented as four-element arrays in the form [red, green, blue, alpha] where each value is a number between zero and one. So in our example, [1, 1, 0, 1] represents bright yellow.