Latest news

Medieval Monday Talk #18 – Pathfinding Overhaul

Greetings, medievalists!

Time for another Medieval Monday Talk. We were pondering for a bit on how to present what we are working on since there is a lot of technical things happening under the hood. But, we’ll try our best. Let’s talk about pathfinding.

When it comes to settlers’ navigation in our medieval colony sim… there is a lot left to be desired. Let’s take a simple movement, like walking diagonally. Here it is how it looked before:

Notice the zig-zag movement. And this is how it will look in the next major update.

It might appear to be a minor thing, but this overhaul is a part of a bigger process that will offer significant optimization chances, easier implementation of upcoming features, and overall better game performance. Those existing issues could not easily be solved due to how the old system was interconnected with the rest of the game. There were a lot of variables, a lot of settlers, and a lot of resources. Calculating all of those options would affect the gameplay but also the CPU.

Within the new system, we implemented multiple agents. Agents represent everything “organic” that moves in our game – your settlers, enemies, and animals. In the current version, the problem is that everyone would try to follow such a system – your settlers, merchants, enemies, and even animals. It would look kinda silly – for a deer to walk over the limestone floors and stairs, just because we established that it is the fastest way for your settlers to move.

Since pathfinding is a big part of the game, this overhaul will allow for a faster calculation for every moving thing in the game and, in turn, allow for better game performance. It will also offer better game experiences. If there is an issue with hauling or ignoring job priorities, we will be able to find it easily and make a solution that will not upset the rest of the systems.

Now, every agent will allow for much more effective, much easier customization to their pathfinding. Animals will have different movement rules and penalties than humans. Deer and rabbits’ navigation will not be affected by flora, and floors will not provide as much penalty reduction as it does to humans (more on that later, below).

With human agents, we can separate how your settlers, merchants, and enemies will behave. Your settlers and merchants will be able to avoid traps with ease (we plan for everyone to be able to activate traps)…

…while the enemies and wild animals will go through them.

Agents will also allow for easier integration with the upcoming updates. Let’s say we plan to implement a new animal within the game (*ominous hint noises*) this new system will allow us to easily define how that animal would move throughout the game. That relates to settlements’ position and location, type of constructions surrounding the animal, and other characters.

Take penalties, as an example, every grid space represents one node. Every node offers a penalty that is calculated by what is exactly that node’s made of and what’s on it. So if there was a bush there, that would cause 3000 penalty points to anything that walks through it, resulting in the slowing down of the character. The simple ground would offer 1000 penalty points, while the floor would provide 250 penalty points.

Everything mentioned above will affect game performance. You might not see it, but it will be felt.

Take this scenario as an example: A settler wants to reach a woodpile. With our old pathfinding system, it would ask if such a pile is reachable and start calculating. The system would take into account every single grid space, the penalties they provide, and thus provide the path for the settler. Now imagine such a simple action for every settler. That action would be very CPU heavy.

Here is an example of A star pathfinding that is used by our game: PATHFINDING. Try building a maze around the end position and once you are satisfied with the result, select Start Search. That is basically showing the current pathfinding logic – in that link, it’s a simplified and slower version, but it very much represents how the game calculates destinations related to the agent.

Thanks to the new region system, the game will instantly recognize where the thing your settler is looking for is. It will inform them about all the necessary regions they need to traverse in order to get to it.

Each region is made from 420 nodes (grid spaces) and it knows what the other regions that surround it are.

This makes calculating traversal significantly easier on the CPU since it doesn’t take the complete map into consideration when calculating. It takes only the necessary regions into account, making the experience much smoother, performance-wise.

Hopefully, this gives you a better understanding of what you can expect in the next update, without the need to go fully technical on it. But trust us – this is excellent news for Going Medieval. Until next talk…

Stay medieval!