Avoid AI teammates from shooting each other

I’m making a tower defense game, the problem is I want to keep the bullet that can harm both enemies and teammates, which they can harm each other when moving on a line. Now, I need a code that can still chase the enemy but avoid shooting their teammates by moving to left-right to avoid their teammates.

you can use a raycaster to detect if the ai is aiming at its teammate. just set the raycast to stop at first object. you can then adjust its movement according to that.