Issues with two or more NPCs arriving to same location


In places like the market, there might be chances that multiple NPCs go to one place for shopping while there is still another NPC in the same location.

Here is a picture for a better understanding:

Suppose an NPC is standing there (on the blue spot) doing shopping while two other NPCs arrive there as well.

In that case in the steering system, these new coming NPCs will strive to go to that location, also the old NPC who now wants to leave might not be able to return because he is blocked by other NPCs. (I have not tested this yet to see how silly it will look in action but I can imagine it won’t look pleasant :wink:)

One solution that came to my mind was to use multiple waypoints instead of one waypoint

so if one location is occupied by an entity, the next waypoint will be used until the first one is released.

Can you think of other (probably better) solutions for handling this issue?

Thanks in advance

1 Like

The way I would approach this is that the market knows when it’s “in use” and is booked out to an NPC. And while it’s in use other NPCs don’t try to use it it until the first NPC releases it

1 Like

I think it depends on your game graphics specs, what kind of graphics you want the player to see .

If you want the player to see a very detailed screen,Your approach is a good decision.

If your camera is a top down view then I don’t think the graphics need to be so detailed just have the NPCs arrive and then delete the NPCs and regenerate them when the NPCs are done shopping.

1 Like

Instead of “walk to waypoint” you could use “walk to line segment” or "walk to bounding box… then they could line up wherever there was room and would always head to the nearest spot.

Else, as you hint you could have multiple way points and turn them on/off as they were occupied.

1 Like

I’m doing this for something similar in my game. I have a trading post where a group of NPC continuously drops off carts, and another group of NPCs picks them up and takes them elsewhere.

So I made an area with 3 parking spots, and if a cart is delivered it gets put in the next available spot.

And if all spots are filled with carts already, any new carts that arrive just get removed and will magically disappear and fade out of existence, so the parking area will never get out of hand with too many carts.

So for your case, I’d probably suggest doing something similar to your idea of putting 3 way points in front of the shop, and then if the spots are all filled, you can make NPCs avoid going to that shop, or depending on your gam’s needs, maybe even make a line area for shops so another 5-10 NPCs can wait in line until one of the 3 shopping spots are open.

That part of the issue might be more related to how your NPC physics system works. In my game, NPCs that are standing on top of each other will automatically push each other apart, and if they both try walking through each other, then one gets pushed left and the other right so nothing ever gets stuck.

I think NPCs blocking each other is a much bigger issue when using rigid body physics like BetterCharacterControl, in which case I think you might need to add some type of steering code for avoiding other NPCs, and also have an organized system for getting into and out of the shop without having too many intersecting paths to avoid as many NPC collisions.