I’m trying to create multiple a way to have 4 factions of ai fight eachother (4 AI FFA rts style).
My wish is that each one aggro on the other 3 when they get close enough.
My initial thought, that I received som feedback on was using tags to have them aggro all tags that aren’t their own(something in style of “attack everything but your own tag” but that comes with some issues that I’d like to hold off on for a bit if possible.
is there any other thing I should look into before starting to work on the system?
I personally wouldn’t use tags for this, as you may find yourself wanting the tags to be shared (“tanks” or “spies”) or something among all units. I’d create a simple Faction ScriptableObject that has information on what other Faction’s you’re currently aggressive (or peaceful!) to, and evaluate that when choosing targets.
public class Unit : MonoBehaviour
{
public Faction faction;
private Unit target;
public Unit FindTargetToAttack()
{
Unit[] units = FindAllUnitsInAreaOfAttack(); // you'll need to decide how you find targets
foreach(Unit unit in units)
{
if(faction.IsHostileTowards(unit.faction) == true)
{
target = unit;
return;
}
}
}
}
The advantage of using a ScriptableObject is you can define all the associated data with the faction as well, such as name, logo, banners, etc. for use in other parts of the project like the UI.
Don’t use tags, either use an int for the team number and check that or use a full on faction type like @GroZZleR suggestes, a bit more work but far more expandable.