So I have a space shooter going on right now, with lots of enemies, and I programmed the enemies so I have to apply them a target in the inspector, which I usually set to the Player. It works very nicely, but I am wanting to make the game co-op also. So if there are 2 different players, how can I set the enemies target?
I decided I have a few options that I have thought of :
- Have half enemies targeted for one player, half targeted for the other player ( enemies could fly right past a player w/ no effort to attack them )
- Find a way for the enemies to search for the closer target of the 2 or more players ( if players are equidistant from the enemy this will be a problem)
Does anyone else have any ideas of how I can incorporate this? And if you do have an idea, could you explain in detail, rather than saying “just do a simple such and such.”
A very simple solution would be to parent a sphere trigger to the enemy and have objects tagged player OnTriggerEnter()/OnTriggerExit() get added to/removed from a target array, then the enemy can randomly switch targets every once and a while.
If you need more complexity than that, I did write a pretty decent aggro system using the built-in networking, but its a bit sloppy. 
Yea I thought about using something like that. I have homing missiles in my game and they use that exact method, however, if the player then escapes that circle, the enemy could potentially go on forever in one direction, never destroying itself. Another issue would be if lets say the enemies are after one player, and another player swoops in behind the enemies to cover their buddy, if they get too close then the enemies will just back off and then try to get behind the second player instead of continuing to go after the first
Do you take into account LOS (line of sight) or direction the enemy is facing?
If an enemy doesn’t have a target, the 1st one would normally be the closest in view, with clever AI maybe even using threat (picking the tough target over a weak target)
Yes Callahan I have, the enemies can only pursue their target if nothing is obstructing their LOS, and then they rotate at a slow speed towards that point, and they are always constantly moving forward at the same speed.
But yea I see what youre saying. Determine targets by what it can see infront of it and un-obstructed. ah hah…