I want to make friendly AIs that could take different positions based of environment query, but I have problem with figuring out how to make one query around position and then tell AIs to take best positions around it without everyone picking the same spot.
UE5 how to make friendly AIs move to X location and takes spots around spot without picking same spot as another AI
not sure how you mean, it sounds like you are doing one query for all the AIs instead of one for each of them, sorry if I’m wrong in my understanding,
but could you not add a filter query that looks for AI and then filter out ones already occupied by another AI?
otherwise it sounds like you are trying to perform all these queries at the same and assign them the best spot for each ai? if so i would probably do this in c++ and perhaps create a array storing each AIs picks for positions and looping through to see if an ai has already chosen this.
the second method mentioned will be really complicated to achieve and will need to have c++ class that all ai have access to and can store the data locally in game. will take a lot of thinking and highly recommend using a activity diagram tool to map out your logic on that one as it will get messy quickly
what I mean is I don’t know how giving generally same command to all AIs with small differences work, you mentioned here that you can filter out positions already picked by another AI, how does that work?
oh so what you mean is I can store already picked locations, but what I am always afraid of is… there is time which every query takes, couldn’t it be so fast that 2 ais pick same position because queries were executed in parallel?
I am saying one query because I think that would be the answer, since then AIs can take any position from that query pool, so my first idea I thought of was “Commander AI” which would do queries and then give out commands to others, giving it natural feel as if commands are actually given through radio
what i mean there is, you can create an environment query that looks for query context attached to the ai so if the ai is already there you can filter it out otherwise you will have to create something that all the ai can send and update on each new query they perform to check to see if its valid, I do believe it is do able but not something i have implemented and i imagine it could make the game lag if too many queries and update are being performed
here is example of what I mean, black is covers, blue is query location, green is picked spots. Maybe then this idea with other entity doing queries instead of AIs themselves might be the thing that would work.
because 2nd problem I see is… error handling, of course there will be situations where either 0 locations are picked or small amount of, so environment query is something I hate for that reason where it crashes whole tree if query return null
this would be the way to do it but you might want to look at videos on how to implement queries in C++ or blueprints as when a query is performed it can generate an array im not sure off the top of my head and it is 2am here so i do appologize if this isn’t as helpful as you like. but you can easily do it in blueprints heres a screenshot of a teleport blueprint that would fire once a query was completed, it would be able to pass the query results as an array but for simplicity we chose the first item in that list. so instead of taking the first you could use it to take the first how many ais you have
if you do the udemy course i did it may help you in what you are trying to achieve and give you a better understanding of AI and EQS
take a look and see if this will help, otherwise i would look at creating a custom event to fire when a query has finished and then loop through that in your commander! hope this helps and really sorry if it doesn’t
Thanks for your help, really appreciate it. yea that would work.
create a condition that checks the return of the query to see if it is less than needed or null and accommodate appropriately, and in situations where i there is less i would create a move to behavior and make the acceptance radius larger than the collision shape so they move close to one of those points.
but flesh it out in blueprints then replicate it to c++ as it will create performance issues if you have lots of ai and/or lots of queries being performed
yea, thanks for your help.
I’m sorry if this is a silly suggestion, but if you gave the spot names as a variable, you could make them booleans set by the AI’s decision to use one. (True/false).
If there’s still a worry about more than one AI heading for a single location, maybe an AI ID could be stored in the spot variable. Then upon collusion, or other factor, it could read the Spot variable again, and if it matches their ID, they continue, otherwise pick another one. The spot variables could also be affected by a player entering it, making the AI choose another one?
I’m not real Unreal savy… but seems like a decent way to blueprint it, assuming there’s not too many spot variables.
Otherwise, making an AI have a preference right from the get-go might be better. That way you could have each of them know their favorite relative positions, as they’re brought in… then re-use it wherever you want. Like first one always goes for spot1, second goes for spot2, etc…
If it’s a “distance from activation” issue where they might be closer to an alternate spot at the time the trigger goes for the AIs to get into positions, then maybe have them compare distances, and take ownership of a spot if they’re closer, like, if AI3’s position is closer to AI2’s spot by at least a certain amount. You have that so that it won’t allow two bots to pick the same spot because they already HAVE a spot, and can’t change it unless they are at least two steps closer to it than the current spot owner…
You still might get a little confusion if two AI’s are the same “closer” distance than the current owner, but if you put a delay timer, or restriction on how many times a spot can change ownership, it should sort itself out. (ie- UponNewOwner says this owner just changed a click ago, or has changed hands X amount of times, so yer out of luck!)
Anyway… if that helps, great… if not, then sorry for wasting your time… just thought it was interesting.