Thanks for the feedback, I'm glad you enjoyed!
The navigation layer is a little complicated, but I use flow fields and hierarchical grids to figure out how to move towards the nearest enemy for each unit. Then, each unit is also treated like a boid (https://en.wikipedia.org/wiki/Boids). They have multiple incentives, including cohesion to allies, avoidance from obstacles (friendly units/walls), alignment with flock, and, crucially, ranged units have an additional force to run away from the nearest enemy within their attack range while their weapon is on cooldown. This creates the behavior you noticed and the tendency for ranged units to hide behind allies and kite enemy units, whereas melee units have an additional force to pursue the nearest enemy rather than avoid.
It's an interesting idea to be able to control a single character or a hero character while the chaotic battle unfolds, though it's also not necessarily in line with my initial vision for this project. I've had less time to work on the game lately so I wouldn't expect this feature soon. Maybe in a future follow-up title :)