When streaming terrain, where to do with agents

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • When streaming terrain, where to do with agents

      First thank you guys, Mike and Rez, for a great book with working resources. Teapot Wars built and ran for me which I find rare for a Game Dev book.

      I have a question that I know doesn't have a "right" answer, but I would be interested in people's ideas.

      What do you do with agents in a simulation type game when you are streaming the terrain?

      If I just loaded them in after the terrain, they would have somewhere to walk but they wouldn't have been doing anything. If they are there from the start they'll either fall forever, or if there physics is off won't be able to interact with each other.

      I've thought about having a lower resolution version of the terrain, or collision that's kept in memory for each vicinity where there is an AI agent...

      but then that idea falls apart if they would try to path to each other because there is nothing in between them.

      I guess another idea is having them only exist in a database.

      Any thoughts?
    • Man, I could probably write an entire chapter (or three) just on world streaming. This is a HUGE topic.

      There are a number of different things you can do so I'll briefly describe a few techniques. It would help to know what kind of game you're making though.

      Low LOD AI
      On The Sims Medieval, the world is split up into a number of lots. Each lot represents a single building (or a part of a large building, like the palace which was split into three lots). We also had two different kinds of AI. There's Meta Autonomy, which answers the question "which lot do I want to be one?" and Local Autonomy, which answers the question "what do I want to do on this lot?".

      Local Autonomy is what most people notice; it's the Sim trying to solve his needs and desires (hunger, energy, social, etc). Sims only consider things on the current lot. Meta Autonomy is very low cost. It looked at every lot and tried to decide where the Sim was needed. In our game, it was mostly based on the desires of the lot rather the desires of the Sim.

      Local Autonomy was very expensive and was only run on lots that were being simulated. Lots were only simulated when a player Sim was on it, or the camera was centered on that lot. All other lots and Sims on those lots were not simulated, with one exception. We still ran Meta Autonomy for all Sims to drive them to other places.

      One caveat to this is that we had buildings, which meant that we could easily hide the fact that no objects were loaded. Not all games work like this, but the principle is the same. In Skyrim, you can't see inside towns. I would be surprised if they did any kind of high-LOD simulation when you weren't physically in the town.

      Kill the NPCs
      This is probably the simplest. You just delete NPCs that are too far away. This was used by a number of older games and works great for action games where most of the NPCs are monsters. You can have permanent spawn points that are apart of the terrain and when those stream in, it spawns the appropriate NPCs. This can also work for very simple towns people, but you won't be able to have extremely complex behavior.

      Light NPCs
      Another solution is to have two versions of the NPC data. The full NPC data is whatever you need to fully simulate the NPC. Light NPC data just has what you need to keep the NPC in stasis and possibly run low-LOD updates. Again, this depends on the game.

      For example, you could have the last known position of the NPC when they stream out and hold it in the light NPC data. They're removed from the physics world so this never updates until they stream back in. Their update depends on the AI. For an town simulation, having a scheduling system is common (we used on on The Sims Medieval) and you just teleport the NPC to the appropriate location when their schedule sends them somewhere else. They don't need to make any decisions since the player/camera isn't near them, they only need to be updated by their schedule.

      When they snap into high-LOD simulation, you need to set up their state to be something reasonable. On The Sims, we have an auto-satisfy curve that determines where to set a Sim's motives based on time-of-day when they come back to high-LOD simulation. We also immediately force an AI tick and push them into an interaction so it looks like they were doing something the whole time. In reality, they were barely there at all.

      These are just a few possibilities off the top of my head. There are many other techniques and hybrids of these techniques. If you can give me more information about your game, I can probably direct my answers a bit more.

      -Rez
    • It's not necessarily for a game. It's a problem from a job a few years ago that I still think about as I wasn't satisfied with how I solved it before.

      A military simulation with real world terrain. The DoD has a horrible thing called HLA. High Level Architecture. Which is supposed to mean if your simulation comply to it, it can interact with any other simulation. The simulation would handle some Intelligent Agents and process their behaviors and interactions in a finer level of detail than the other simulators on the Network.

      When I was working on this project, it's completed now. I choose to limit the terrain patch to a small area, like 5k square, and just kept it in memory. The target system was a scientific computer, so it had high memory. The Agents went about this small area and had their interesting interactions, while it would broadcast their ids and locations over HLA, and would also puck about units from other simulators on the Network.

      The problem was the size of the area the Agents had to work in. I had a whiteboard design for a paging system of terrain but I never completed the path-finding scheme for it. An area of around 84 square kilometers would have been ideal to be able to cover live, with a high level of AI simulation going on for Agents spread about the area.

      It's not something I'm specifically working on now, but because I mainly do SeriousGames and have experience doing Military Simulations the likely hood of my working on something like this in the future is possible.

      It was the first major project I led and I think to myself, How could I have done this better, or what would I do next time.

      My current day-job project is more like a Game and has smaller area to deal with so I'm not pressed to find a solution to this right now. But, it's always a curiosity I return to when I'm thinking about AI in military simulators.

      But as a side project I'm mor einterested in making the engine than the game. I chose to make a Minecraft type clone. I was thinking of what to do with the AI's when they are not on terrain that's loaded. Loading them in, when they come in range and skipping them into a believable action would probably be great here.
    • That makes sense. These kinds of problems really come down to the trade-offs. What is the problem you're trying to solve and what trade-offs are you willing to make? Military Simulation is a very different world from games, although we do have some similar problems. I have a friend over at Lockheed Martin and we chat about this stuff from time to time. It's not really my thing, but they do have some interesting AI problems to solve. :)

      -Rez
    • I know Kevin also. It's a small club.

      Off the top of my head tradeoffs.

      1. Doesn't need anything in memory that isn't being rendered.
      2. A lower level of detail for physics, that aren't on camera.
      3. No animation stuff needs to be in memory that isn't being rendered.
      4. Path-finding and traversing could be at a lower level of detail when out of site.

      I think they would still have to be able to path-find, and do all their behaviors. But, it could all be a database game.

      The events would have to be recorded though, so on a reply moving the camera about would show them to have been doing their jobs, even though at simulation time they were just have values flipped in their db tables.

      That's a good way of starting a design. Asking what trade offs your willing to make.
    • Right! I thought your name looked familiar! I didn't realize you were another member of the guild until I saw your email.

      A typical solution for pathing is to use hierarchical path finding, which are basically just a graph of waypoints. Movement is just a LERP along the arc between those waypoints. The idea would be to make them as coarse as possible, maybe just the network of roads. When you stream in high-LOD terrain, the entity is instantiated at the calculated point and re-plans their path.

      I think you're right, I think it's a database game. Although I'm not sure what you'd gain from having them act on specific behaviors. For example, if a guard is supposed to be patrolling a wall from 6am to 10am, I don't think it matters if the low-LOD version actually simulates that. It should just put the character to the appropriate node at the wall and then do nothing until the high-LOD area is streamed in. Then he'll be instantiated, run an AI update, and start actually patrolling before the player ever sees him. The illusion is that he was patrolling the whole time.

      -Rez
    • I guess what I think you'd gain, or the point of actually having the agents do behaviors in the db is so they could effect each other over time. So regardless of player input the Agents will be going about their own agendas with each other.

      Part of the "game" for the player would be to discover what those interactions and connections are. Or, to see that things were going on when they weren't there. Such as the BlackSmith being put in the stocks for making a poor choice of comments to the Mayors' daughter. Townsfolk that noticed the event would remember seeing the Blacksmith put in the stocks etc.

      I haven't played Sims. For all I know you are all ready doing something like that.