>>49615219It probably just draws a line between the two mon, then calculates how much either of the mon should move backwards to reach the desired distance. If the calculated new position for the mon is reachable, it simply tells the pathfinding engine to make the mon go there, and the pathfinding engine quickly realizes it needs to take a detour to reach there. If it fails for both pokemon, it tries rotating the line along the axis of either pokemon and tries again.
Sending out a mon likely uses a similar method except it tries multiple positions, so this is only necessary if there wasn't enough space in the direction the mon was sent out.