Assigning the generated animals an arbitrary trajectory to the targets

I want the generated animals to set a trajectory on which they will start walking after appearing. Provided that moving along it, if they meet a certain structure, they will attack it, as soon as the structure is destroyed they will go further along the trajectory until they meet another one, and so on.
Also, I need the animals to be 2 types: from the team of players 1 and from the team of players 2 and attack players (opposite team) that get in their way, but as soon as the player is away from the path a certain distance they continued on the specified path.