I have code snippet to sort the targets based on distance to the attack troops the code change is below: In the after the line 55 in attackMoveToCC.js, add the following lines //Sort targets based on distance targets = targets.toEntityArray().sort(function(a, { var pos = pending.getCentrePosition(); return (VectorDistance(a.position(),pos)-VectorDistance(b.position(),pos));}); I have tested the code long back, please you also test this and commit