This is one of those situations that’s difficult to do with expressions. The reason is that for the position expression of the “pushee” to be able to figure out where it should be, it needs to know the entire history of the movement of the “pusher”. The only way I know of that will work is to have the expression loop through every frame of the timeline to figure out where the pusher has been. It can be done, but it gets a little impractical if your comp is long. Anyway, here’s an example that works on the x axis. It assumes the pushee starts to the right of the pusher.
// assumes this layer is to the right of the pushing layer
P = thisComp.layer("pusher");
// find pusher's max movement to the right so far
maxX = 0;
for(t = 0; t <= time; t += thisComp.frameDuration){
x = P.position.valueAtTime(t)[0];
if (x > maxX) maxX = x;
}
if (maxX + P.width/2 + width/2 > value[0]){
[maxX + P.width/2 + width/2,value[1]]
}else{
value
}
Dan