Fixing Sundermead's CORE MECHANIC!

Saturday, December 3, 2022

Watch the video here!



For the last year and a half, I’ve been working on a life sim all about building a new settlement. The core mechanic of this is asking people to come to your new settlement to live and work. From Sundermead’s inception, the way this was done was, initially, threw the summoning stone. This was an item you’d use to talk with and make sacrifices to the gods - one of these sacrifices allowed you to start inviting these people by asking Woden to find your settlement’s first villager. After three days he’d send Farmon, a shipwright, to Sundermead and from there you’d complete quests and invite the next character, through that character you’d get the next, etc. etc. 


The problem with this system is that the summoning stone is also used for lots of other things, such as making sacrifices for rain, sacrificing food for new seeds and so on. This meant that the character inviting system kind of took a bit of a back seat to the rest of the game and made the game appear to be more of a survival game than anything else. The plan was for it to be Stardew Valley with Minecraft elements but it ended up being the other way around.

Having a game presenting itself differently from what is intended is a recipe for disaster because players won’t really know what it is they’re going to get. This needed sorting out asap. I realised that the core of the problem was in the summoning stone because, not only did it allow you to do too many things, but it was also extremely clunky. To replace it, and make the character inviting mechanic front and centre, I decided on a ledger item. At first, I planned on making it so, when you started a new save, the first thing you had to do was place it down somewhere - this location would be the centre of your little village.

I realised that making players choose something so important right off the bat might not be such a good idea and might even put players off playing straight away. After some thought, I settled on the idea of the ledger item. Instead of placing it down, it was now an item that you’d keep in your inventory, and like your tools, it can’t be sold. I then wanted this ledger to behave similarly to a tech tree, where unlocking one thing unlocks two more, and so on. 


The rendering of the tree was actually the most challenging part of the whole system - I wanted a way to automatically draw the tree without any input from myself (except for the tree’s progress) - the positions of each element needed to be entirely procedural and also to be able to sort themselves out if I decided to change anything. For this, I went down a huge rabbit hole of tree-rendering algorithms, eventually deciding to go with the Tilfoid-Reingold algorithm


I’ve got to say, I’m extremely happy with how it came out. Next, I needed to set up conditions for inviting these characters. To do this, I just used Unity’s scriptable objects which allow me to just drag and drop them into my little graph. Each character has a default condition, this being whether a bed is free or not - after that, it can be anything I want really: time of the month, whether a quest is completed and so on. There are also scenarios, like with the Shipwright, when a character’s bed needs to have certain conditions - for example, be near water. I was able to do this using virtually the exact same system. 


Any unmet conditions will display in red and any met conditions will be in green.



I thought it was about time I talk about how my AI works. In the past, I’d briefly mentioned my AI package system which was inspired by how Bethesda do it - (pop in from the side) It’s actually a free unity package - (pop in from the other side) see the link in the description - if you want to you it. But beyond this brief mention, I’d never really gone into detail as to how these AI see and interact with the world.


So firstly, how does my package system work? Well, an AI actor, as I call them, has a list of packages, prioritised by the order said list is in. For every tick (not frame, because I also have an AI timing system), the AI will go through each package until it finds one whose condition is me - this is why the priority order is important. Some packages also have a completion conditional that must be met, so the AI won’t search for a new package until the current one is complete. Anyway… once a new package is found, it initialises it using an OnStart method and then will begin to tick it. 


Things start to get interesting once the AI package gets ticking. This is because each package has a behaviour tree within it. This is done using a package called fluid trees. Each time the package ticks, the behaviour tree also ticks. Before creating my package system, each actor had one massive behaviour tree but I found this very difficult. Now each piece of behaviour has its own package and also allows for much more extensibility, modularity and maintainability (all the things a programmer wants). 


Now that the actors can execute behaviours, they needed a way to interact with things in the world. This is done using my actor interaction component. I can simply drag this onto an object, define possible positions for the ai to interact with it and also set some behaviour, such as playing an animation once the actor gets there. 


The next question is, well how do these actors find these objects to interact with? Well, luckily Unity has a little feature called Physics.Overlapsphere. This function is just a way to query the physics system by position, layer and distance. Luckily, my interaction component automatically sets its positions to said layer. This means, when I run this query, I can just search for the ActorInteraction layer, saving a tonne of performance. Here are a few examples of this system working. Notice how the Anvil has two possible positions, yet Ceada never chooses the one that is blocked off. This is because, when an actor first finds an interaction object, it asks said object for any positions that aren’t obstructed. This way, actors will only ever interact with an object in a way that makes physical sense!


If you like the look of my game, I’ve got a Steam page where you can go and wishlist it as well as a Discord where you can chat about the game and keep up to date with more granular updates. As well as those two, I also have a Patreon now, with the two highest tiers giving you access to the game right now to help me test it and make it the best product it can be!


With all that said, thank you very much for your time!

~Joe