Aug 11, 2015

Posted by in Game Development | 0 Comments

Unaccompanied Miners

The problem du jour: Getting miners back to work.

No, it’s not a union thing. The miners start out working just fine, anchored slightly away from an asteroid where we can assume they’re firing their pew pew lasers into the chunk of stone and collecting the liquid metals they release. Eventually, though, they fill their holds and have to head back to their depot to drop off the cargo.

Now, no one begrudges the miners for wanting to spend some time at the bar while in port, but they do need to get back out there eventually, so they suit up, buckle up, and fire up their engines to head back to their asteroid.

Thing is, their hearts and minds are back at the bar, so they figure that since they don’t want to be at the asteroid, they shouldn’t stay at the asteroid. Instead, they bounce off the trigger sphere and head back to the station.

One problem is that miners need to crowd around asteroids to do their work. In order to ensure that they aren’t just spawning on top of one another I’ve set them to spawn in a kind of circular array around the point of interest. Originally this worked great on spawn, but when they went to the station and returned, they were returning to the transform position of the asteroid, which meant they’d stack. In an attempt to combat this, I set their “asteroid waypoint” equal to the point at which they spawned, which is a Vector 3 in the array mathematically spaced around the asteroid. They spawn there, and they return there, and technically they shouldn’t overlap with other mining NPCs.

While that works just fine, the NPCs don’t actually spawn inside the trigger sphere that tells them that it’s time to start mining. When they return to the asteroid, they stop just short of entering the sphere, and since they’ve effectively reached their destination, they know it’s time to switch to the next destination — the station — so they turn around and head back to the bar.

The way I see it, there’s a few ways to approach this. One is to figure out another way to get these guys to spawn inside the trigger and record that position as the start and return location. Alternatively, I could do some math and move the return positions inside the trigger sphere. Changing the way the NPCs are spawned around the asteroid is going to be tough, since the code I have that does the placement was taken en toto from an example on the Internet, and like most Internet code, it works, but it’s pretty black box to me. Another option is to add six empty game objects around every asteroid construct and use those as target nodes, putting them inside the trigger. The downside to that is that it’s overkill.

Leave a Reply

What do you think?