Here’s the semi-final-ish-sorta example of NPC traffic patterns in a sector.
In order for the sector to seem populated and active, NPCs need to go about their business at least to the point where it looks like they’re getting things done. My recent focus has been entirely on getting these little prefabs to move around according to their “jobs”, which has been both easier than I thought, and also a real pain in the ass.
The white elements are “nodes”, populated centers of activity, and are labeled according to what they represent. Their identities are defined by components and tags for ease of use. They also have other components on them (or they will at some point), but for this test they’re just 3D prefabs labeled according to what I need them to be.
Blue prefabs are the cops. Their job is to patrol between nodes and keeping the peace. They’ll intercept pirates and might hassle the player under certain circumstances. Their route is calculated by taking all objects in the sector that are STATION or JUMPGATE, shuffling that list, and then moving between those object positions in a loop.
Red prefabs are merchants. They were supposed to be the most difficult to work with, but that wasn’t actually the case. Merchants jump in at a gate, travel to and dock at a station, and then undock and leave through another gate (could be the ingress gate…it doesn’t matter). Their pathing is simple: pick a random JUMPGATE object, a random STATION object, and another random JUMPGATE object, in that specific order, and move between them. Unlike the cops, though, when a merchant type enters the trigger sphere of a station, it becomes inactive for a semi-random amount of time. When the time is up, they reactivate and move to the next node. When they enter the gate trigger sphere, they become inactive until we need another merchant from the pool.
Green prefabs are miners. Their job is to stay motionless, mostly, at a “home” asteroid (if there are any in the sector). Every now and then they’ll pick a station to fly to, dump their cargo, and return to their home asteroid. Unlike merchants and police, the miners need to stay motionless most of the time (eventually when they have models, they’ll bob around and shoot mining lasers, but otherwise won’t move), and then randomly move to a station where they use the same docking timer system that merchants use. Miners were tricky because I didn’t want them to bunch up on one rock, and when they do (through happenstance) they had to not sit on top of one another. I had code that places objects around a central point, like positions on a clock, so I used that in case multiple miners get assigned to the same rock.
Problems With the Current System
If you watch the video, you may notice a few issues: