Follow objects as if there was a magnetic field using animation Nodes
Method 1 (Recommended)
You can evaluate Fcurves to get trailing or attractive effect. You need a source object with location keyframes. Then follow node tree given below.


Method 2
We can also do this without keyframed source object by storing positions of object.

For storing object transformation as Matrixlist:
setattr(AN, &quot;store&quot;, Matrix4x4List()) if frame == 1 else AN.store.append(x)
Get stored Matrixlist:
AN.store[-amount:]