If the layer you want to trace is outlined by a mask, paste that mask into the position property of a Null, spread the resulting keyframes out to the timing you want, select the “Strike” lightning type, and apply this expression to the Direction parameter:
fromComp(thisComp.layer(“Null 1”).position)
Dan