NavMesh : Resolving Destination Conflicts...

Hi

I have a scenario where I have multiple NPCs in a crowd.

I’m utilising NavMeshAgents to handle navigation around a building layout…all that is fine, and the agents can find their way to the specified destinations all ok.

Here’s my problem…a room within the building has multiple preset destinations for the NPCs…the NPC script selects a destination at random and heads off towards it.

Sometimes, 2 NPCs select the same destination (I actually want this to happen) and then there is a little skirmish at the destination. I’ve figured out how to handle it if a NPC is at the destination and another comes along.

However, my problem arises if 2 NPCs are set to arrive at the same time. The NavMeshAgent never gets to fulfil it’s navigation routine as it doesn’t arrive per se…so you end up with 2 NPCs pushing against themselves around the destination point.

Any ideas how to go about resolving this conflict?

I’m trying to think of a way to say (in pseudo)…

if character is within a certain distance of target and has been for a set amount of time then select another empty location, according to the database.

but then I can see problems like if they arrived EXACTLy the same time, then they are likely to leave at EXACTLY the same time, unless I create a little variation in the time until a resolution is attempted.

Also, I have an exact number of destinations equal to the number of NPCs attempting to enter the room…perhaps it might be better to allow a little overhead so there is always some empty slots…thinking out loud here.

I can probably resolve it myself eventually , but I was wondering if someone had any suggestions to assist me getting there sooner.

By the way, I’m quite a noob in terms of Unity, but have been a programmer since the ZX days.

Any help, greatly appreciated!

Also ,I have an NPC AI script which is a component of each NPC, and this scripts handles all their own target selections.

Might it be better to have an overarching waypoint control script which assigns destinations to the NPCs? This might be easier to handle as each NPC will be dealt with in turn, rather than each NPC simultaneously selecting a destination.

(this is where my SQLite is falling over, as each NPC is accessing and selecting at exactly the same time, so a destination which is available in the db, is selected multiple times before it is marked as taken)

simple solution would be to have them stop and wait a random amount of time when they bump into someone

if they get to the end of their wait period and still cant move, they choose a new destination.

Yeah, thats a good idea.

I briefly did some work on the overarching scripts method this afternoon, and it works everything out surprising quickly… I was expecting a bit of a delay between each npc starting off but they all started moving at almost the same time…thats with 10 NPCs…will have to give it a try with the 50 odd I’m going to need for my game and see what happens. The elements of the game means it usually means all 50 odd will require a destination assignment at the time most of the time, but with a bit of intermediate variation thrown in too.

I’m going to try it again tomorrow with them sharing some destinations and then have the control script handle the reassignment, and add in the wait theory and see how that pans out.