Villager Gathering AI

Hi guys,

Our game, Indigenous, involves players building villages by commanding their villagers as well as working alongside them in a mashup of third-person survival and RTS game modes.

I’m currently working on commanding the villager to gather items - more specifically in the stage where the AI locates the item to gather. I’m trying to find a “best practices” scenario for the gather logic.

It’s not a hard problem to solve if you ask the AI to gather wood since wood is everywhere, but what if the player asks the villager AI to gather a rare mineral that’s in a set of caves across the island? The player doesn’t know exactly where the mineral is - only that he knows is probably in those caves. Do you run a sphere check on the entire island? That seems like a performance killer to me…

My other thought was to break the island into named zones and throw all gatherable items into a data table alongside each zone they exist within, then the villager AI can walk to the zone then cast a smaller sphere trace.

Of course all of this has to be procedural and run in real-time, since our islands are procedurally generated…

Does anyone else have a better idea? I’m not experienced in AI at all so I’m really just trying to use intuition, which is likely leading me to an incorrect solution.

Why don’t you just send your AI off into a random direction and check within the Line Of Sight whether they found the desired resource every tick? If the AI doesn’t find X resource within Y Units of Z point then return or go in a different direction.

To me that seems to lead to really “dumb” AI. If that resource is only in one section of the item the villager could go off in the wrong direction and the player would be frustrated, knowing he’s blindly searching. We’re talking about an 8KM island.

Yes but you already said the world is procedural generated, so what’s the difference from a player walking in the wrong direction and an AI doing it?
Both would have to go through the same process of Trial and Error.

If you are smart about it, you can have the AI’s get notified when another AI finds a desired resource so that all AI’s when looking for resources will go to the same place.
If you make the AI even smarter you’d have the option to set whether an AI will look on it’s own or follow everyone else.

Assume the player knows the area in which the item exists but not the exact spot. The player can only tell the AI to “gather item”, not where to gather it. The idea is if the player finds the item in the world, they then learn a few things on behalf of the AI:

  1. What the item is (e.g. wood)
  2. What asset it comes from (e.g. wood comes from trees)
  3. The general area in which the player found it (e.g. trees are on the north side of the mountain)

But making the player tell the AI where to go is cumbersome in a game such as Indigenous where you’re trying to manage villagers and play in third-person simultaneously. The villagers just need to know where to go. If the player has never found the item in question, the AI won’t know where to look but the player also won’t be able to ask them to gather that item. Instead, the player can tell the AI to explore the island, which is a completely different process (and one your suggestion lines up with better).

These are two things I will be adding for several reasons, gathering and otherwise.

As a followup, isn’t a navmesh just a mesh? Could I just figure out whats in each triangle of the mesh? I don’t know with UE4’s fancy auto navmesh generation if it’s possible to pull that information.

It seems like the information can be shown in UE4: Imgur: The magic of the Internet

But I’m not seeing a way through blueprint to access that data. I wonder if this is a C++ only thing.

I am not sure. Maybe you’d have to expose that to blueprints through C++ or use the Unrealengine.js module recently released instead to try and do it that way.

A Navmesh is just an approximation of the geometry its covering.

It seems to me like you need a slightly more thorough way of interacting with your AI. Maybe you need a more in depth resource search order the player can give an AI. Say for example you can open up an UI map that you can then tell an AI Unit to search for X resource in a particular area. That way your targeting the AI to the approximate location that you may know of a resource to be located.

Random searching by the AI isnt a horrible idea, if you tie your resources to spawn at particular areas of the map, say you may find metals more often in a mountainous zone, once the AI crosses into that type of area it may search more thoroughly since it has knowledge that metals are more prominent in that zone.

This is what I tried to get at, yeah.

You guys are suggesting that I have the player pick a point on a map and tell the AI to search around that point. That sounds like a UMG call which associates the map location with a physical world location behind the scenes, then spits out a vector location for the villager to walk to, then once the villager reaches that location he starts searching via traces.

My original response mentioned that we didn’t want to give players the ability to mark on a map, but I suggested feeding location data into the request and having the villager walk to a location that is likely to hold those materials then do tracing.

I think we’re discussing the same thing? I just need to figure out how to map locations dynamically when the island is generated. This is why I was interested in the polygons from the navmesh, because they’re literally a real-time mapping of the terrain.

Could you per-chance give us screenshots of how a player interacts with an AI?

I think the best solution is what you mentioned in your 1st post: create (uniform) zones, and add them properties like what resource is there. They can be made after map is generated, by cycling through resource actors, get their position and assign to a zone. Then mark the zones as discovered/unknown, that can change runtime. It can be enhanced by putting some pathfinding data into the zone system, thus finally you can simply use potential fields to get resource zones and storage zones to move the gatherer out to collect and back to supply the resource…