Characters follow a path like MOBA Games

How can i make some enemies follow a path like a MOBA Game(when the hero is in range they go in the hero direction but when the hero is out the range they follow the specific path)?

Thanks

The short of it is that you need a state system as well as the existing path that you want to follow.

The state system can easily just have a couple of states, (attacking, patrolling, returning) When you start, the mob starts as patrolling, where you simply follow point to point your patrol path. When the player comes within X distance, it should change the state to attacking (and retain the point where it changed state at) The enemy walks to the attack position of the hero. Attacks. One of 3 things happen. It walks so far that it has moved beyond a limit where it will stop following and return. (returning) It attacks the player and is killed. (killed of course) or it attacks the player and wins, where it returns. (returning)

When returning, it simply returns to the point where it originally changed to attacking, and continues it’s patrol.