So I was following this tutorial here and I wonder how do I loop through all of my players who connect to the game to find the closest and tell ai to follow this player.
I found some complicated ways to loop through specific actors’ classes, however, I believe, this is not what I am looking for.
So if you ge the idea, any help will be appriciated.
Get all player, get distance of 2 points (player location, ai location), find the smallest value, call FollowActor and set that player as the actor to follow
you can make this check into a task in a behaviour tree and so that it checks it every tick or something like that to make sure it is always following closest player. You can also use tags. tags are amazingly powerful as you can get all of one type of blueprint and filter based upon the information in the tags.
EQS is made for this sort of thing, check out this documentation and see if it makes sense to you. With EQS you can easily do other tests like visibility to see if the AI can actually see their target, it then gives a score depending on the best result fitting your criteria.