I would do this in the following way:
AnchorPoint expression for the top layer
var myWidth = sourceRectAtTime(sourceTime(0),false).width;
var left = sourceRectAtTime(sourceTime(0),false).left;
var myHeight = sourceRectAtTime(sourceTime(0),false).height;
var top = sourceRectAtTime(sourceTime(0),false).top;
[left+myWidth/2,myHeight+top]
AnchorPoint expression for the bottom layer
var myWidth = sourceRectAtTime(sourceTime(0),false).width;
var left = sourceRectAtTime(sourceTime(0),false).left;
var top = sourceRectAtTime(sourceTime(0),false).top;
[left+myWidth/2,top]
AnchorPoint expression for the mid layer
var myWidth = sourceRectAtTime(sourceTime(0),false).width;
var left = sourceRectAtTime(sourceTime(0),false).left;
var myHeight = sourceRectAtTime(sourceTime(0),false).height;
var top = sourceRectAtTime(sourceTime(0),false).top;
[left+myWidth/2,myHeight/2+top]
Position for top
L = thisComp.layer(index+1);
H = L.sourceRectAtTime(0,false).height;
diff = 75;
S = L.scale[1];
P = L.position;
[value[0], P[1] - diff - S * H * 0.005]
Position for bottom
L = thisComp.layer(index-1);
H = L.sourceRectAtTime(0,false).height;
diff = 75;
S = L.scale[1];
P = L.position;
[value[0], P[1] + diff + S * H * 0.005]
What we have done is:
Put anchor point of the top layer to its bottom.
Put anchor point of the bottom layer to its top.
Put anchor point of mid layer in its mid.
We have done these to have an easier position expression.
The position of the top layer is the position of the mid minus half of it’s height minus your difference. We multiplied this by scale*0.01, because sourceRectAtTime does not include the scale in it’s value. So that 0.005 is just the 0.01 from scale multiplied with the 0.5 from height.
Same for the bottom layer, but with plus instead of minus.
You should take in consideration that these layers are in order in timeline: top, mid, bottom. If you have a different order, you should link your mid layer in both position expressions, on the first row. So instead of L = thisComp.layer(index-1); you will have something like L = thisComp.layer(“HERO TYPE”);