Queue System - Waiting for a free spot to set as an agent destination.

I’m currently working on a simple shop simulator, mainly to practice scripting and some non -complicated AI.
I figured out almost everything so far, BUT, how to make the customer check if someone else is currently at checkout and if so take a place in a queue. The customer spawns at the shop entrance, takes a second to evaluate if shop has any shelves to approach, if true starts to search and approaches a random one. And then the checkout… Any ideas on how to approach this? Should i predefine waypoints as the queue spots? But then how do I handle that?

Hey there,

i’d suggest you give your “Shop” some kind of “Checkout” script that the AI can access. That Checkout script should have a … “Queue” :D. For implementation i’d suggest to use a List for that.

So you have a public List<YourAIs> checkoutQueue that the AIs then can enqueue to. Easiest to go from here would be that the AIs always enqueue as soon as they want to check out. Though this should be handled with care since if A is far away from the counter and queues first, but B is closer and is second then B will wait for A to reach the counter even though B would have been at the counter first.

Then you have 2 choices: Either have a List of Waypoints that you assign to the AIs (and then reasign each time you remove the guy at the front of the queue ) or (which would be my personal favorite) have them queue randomly by telling them to move next to the guy which is in front of them in the queue. The latter would result in random queues throughout your shop which could be either hilarious or really shitty :smiley:

Then to handle the distance problem: Instead of queueing instantly you should have each AI move towards the end of the queue and then actually enter the queue as soon as they are physically present. Also each AI which is currently moving towards the queue needs to update it’s destination position as soon as the Queue List was updated.

In case you need more help regarding implementation let me know what is unclear in detail together with some codesnippet and we can work from there.