[Unity3D Hex Map Game Dev] 43: New Unit Type - Scout / Wanderer

Опубликовано: 30 Март 2026
на канале: Re: cOg Mission
457
21

Hello Unity fans and welcome back to my game development series. We’ve been stuck on 4 specialist unit types for a few months now while looking into threading, optimisation, progressive building and our task queuing system. We’ve currently got builders, woodcutters, stonemasons and farmers working pretty well, but today it’s time to meet a new unit type.

➤ Subreddit:   / world_turtles  
➤ Patreon:   / recogmission  

In the beginning of the game, this new unit type would basically be a scout, exploring the map so you know in which direction to plan your expansions, and gathering other useful information and even items to kickstart your game. However, as this functionality becomes less important later on, I’d like this unit to apply to higher tier versions of it, so I’m going to call these units wanderers for now. To me, the most remarkable thing about adding a new unit type to the game is how relatively easy it was due to so much of the basic functionality of the game being properly designed and implemented in a generic and parameterised way at this point. Let’s see what I mean by that.
I’ve spent the last few months really trying to polish, optimise and generalise a lot of the most basic building blocks of the game, developing well-defined sub-systems that handle specific functionalities but also integrate well with the other systems in the game. Our builders, woodcutters, stonemasons and farmers are able to perform a substantial amount of work through the automated task system that runs on a parallel thread, while map exploration and fog of war runs on another parallel thread. Finally, terrain triangulation runs on yet another thread. This frees up the main thread to largely perform what cannot be passed on to parallel threads, leading to more, and more stable, frames per second all around. Another part of the game that I’ve expanded on a lot during this process is the path finding algorithm, and today we’re going to add something new, and very useful, to it.
Just like we’re able to tell our woodcutters which areas to target for chopping down and planting trees, we also want to enable the player to specify the areas on the map to focus on when exploring. Please ignore the placeholder icons of the UI – I will eventually get decent icons for everything. With the area specified, we now want our wanderer to find the closest unexplored segment to the target area and explore it. So, we need to add the ability to test a potential target segment for unexplored neighbours before allowing it as the final destination to the search algorithm. When he gets to this segment, I currently just have him put down his basket, wait a while, pick up his basket and get going again. However, I’d probably want to add something more meaningful here, like making some notes and drawings. But for now, let’s just keep going. He now looks for the next closest unexplored segment. However, if we always look for the unexplored segment that is strictly the closest to the target area, the wanderer’s patterns of exploration would become very unnatural, since he would often walk from his position all across already explored terrain to the other side of the area to get to the unexplored segment that is now the closest to the target area, especially when the player changes the target area. He may then walk across already explored terrain again. Sure, he’d keep exploring in this way, but it would be rather inefficient. We’d much rather he’d walk along the arc where the explored terrain meets the unexplored terrain. This would prevent him from crossing already explored terrain so frequently, and actually gives us a lot more return in terms of area of terrain explored, for a slight relaxation of the strictly closest unexplored segment rule.
There’s another consideration to keep in mind. While the nature of his tasks means he won’t visit his home as frequently as the other units, I think we would generally require our wanderer to return to his cabin once in a while, let’s say after he has stopped 6 times to jot down some details and drawings.