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!