How to make AI follow the closest character in a multiplayer?

Greetings!

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.

true. Btw he does not have to do it every tick, every one sec should work too

Thank you for the reply. I have some questions, 'cause I’m still kinda new to blueprints :

  • how do i get all players?
  • I can find the smallest value between
    2 points by using “vector - vector”
    node, can’t I?
  • where can I find something to read
    about tags?
  • Get all actors of class → select player character
  • vector1 - vector2 = vector3 → call the “length” function for vector3

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.

More information here - https://docs.unrealengine.com/latest/INT/Engine/AI/EnvironmentQuerySystem/