Download

Programmatically quantifying location

I’m building a living world game, and I’m working on giving NPCs the illusion of agenda: it should look to the player as if they’re moving around the world pursuing their own goals and lives, but obviously nothing is actually happening to an NPC unless the player actually comes near them, at which point they spawn and make like they’ve been there all along.

It seems like the only data I need to keep track of at all times are a reference to each NPC, that NPC’s state (at work, taking a nap), and that NPC’s location.

The first two are trivial, but I’m really debating with myself over how to quantify location, as nothing else in my game specifically needs this. Since AI logic centers around finding and using interactable objects like in The Sims, the best idea I’ve had is to child every interactable Actor in a room to some master objectManager Actor, whose only job is to retain a reference to the interactables childed to it. When the game starts my master AI controller can generate a list of every objectManager in the game, and whenever the chunk an objectManager is in loads, that manager queries the master controller for references to every NPC currently using objects it manages, and spawns those NPCs appropriately.

This sounds okay, but a little shaky: is there a design pattern I’m missing here that would be a better fit for the task of tracking and spawning/despawning NPCs in a large world?

How about liberally using spawnpoints in your levels. Then you only have to decide which spawnpoint is the best location to spawn a character at any given moment. So if you’re character is a shopkeeper and is currently working, spawn him behind the counter of his shop.

That’s another pretty decent option I’ve considered, what’s making me wary about it is that spawnpoints require manual configuration, doubly so if they’re going to contain specific information about where or what they are, and since my world is going to pretty large I’m trying to minimize the amount of manual configuration necessary.

You could store the information in a data table and then link the spawnpoint to the entry in the table with an id. So you won’t have to touch the spawnpoints themselves once they are placed.

Assuming that hardcoding locations ends up being the best option, how would you recommend letting each NPC figure out what constitutes character-specific locations like Home and Workplace? The most straightforward approach I can think of would be to give each character’s data class references to homeSpawner and workSpawner, but there are going to be thousands of NPCs and the NPC data file is probably going to be the most frequently moved and copied component of the entire AI system, so I’m trying to keep the amount of data it actually stores to as little as possible.

Information has to be stored somewhere. A data table or database would be my choice. If you want to reduce the data stored, you’ll have to put your NPCs in groups, that share behaviour. Have a look at Assassin’s Creed. There are hundreds of NPCs on the streets, but most of them just run in circles. There’s no need to have more complex behaviour for pedestrians, as very few players will take the time to stalk them (except me :)). In the end you can concentrate on the few NPCs the player will actually interact with.
Since you’re only interested in the illusion of purpose, you don’t have to overcomplicate things.

Alright, thank you very much for the elaboration- I really appreciate the feedback :slight_smile: