Ah! Yes! I finally got a rough draft of GOAP up and running. It took a few days of banging my head against the wall but I finally got it! It wasn’t actually that difficult in the grand scheme of things. I probably spent most of the time just staring at the screen trying to wrap my head around this four dimensional non-sense. In order to create a GOAP system you have to think about AI from an entirely different angle. You can’t just go down a finite state machine style checklist of obvious choices anymore. Instead, it’s all abstracted to hell and back. Everything has to be decentralized but also compatible.
The current implementation isn’t very faithful, though. That’s why I’m only calling it a rough draft. I took a lot of short cuts in order to get where I am now. I did this to reduce the overall complexity of implementing something with such a foreign design concept. Instead of having to simultaneously develop new mechanics on multiple fronts I just focused on the most important one. The automated goal / action system!
I left out things like the cost / weights stuff or support for multiple goals and action paths. The deer only have one goal, which is to eat, and its always active. They’re basically being forced to gorge on those delicious berries non-stop! There’s also only one possible path of actions they can take in order to eat – which is find berries, path to berries and then eat berries. The important part, though, is that they’re figuring out how to do this all on their own. I’ve verified this by randomizing their actions prior to analysis. They figure out the right order of operations no matter how much I mess with them.
Anyway, here is the first ever video of it running! It’s just a dumb little deer eating dumb little berries. The white D is the deer and the pink bush looking things are berries.
The next step was to test its responsiveness. I added a respawn timer that adds new berries to the world once a timer is reached. It’s a good thing I did this because I noticed a problem. The agents aren’t analyzing their environment in real time. They get a path of actions and stick to it until completion even if a better path shows up. The deer will find a berry and move towards it as expected but if a new berry spawns that is closer than their currently targeted berry they wont change targets. This is a performance heavy feature but its kind of the whole point of GOAP. I’ll get it patched up soon.
I then took a risk and added another deer. Everything actually worked without issue! I was really expecting a crash or some kind of conflict to arise but nothing bad happened. However, as you may have noticed, their is something strange going on. It’s not a bug or anything, though. It’s more like a quirk.
That quirk is that both deer eventually get kind of stuck doing the exact same thing. This is happening due to how the berry search works. The game finds all the berries and directs the agent towards the closest one. This means, then, that the closer two agents are and the fewer berries their are the more likely they are to start going for the same berry. Eventually they’re on top of each other and moving in perfect unison. This would happen less if the map were bigger and I didn’t allow agents to occupy the same tile.
The below video has even more deer in it to help you see what I’m talking about. I also dramatically increased the berry respawn rate to try spreading them out more but it didn’t really help. Even with so many food options the dummies still get all stacked up! I’ll have to add some kind of randomization or something to prevent this. also cleaned up the debug stats and added a guide line that connects each agent to their debug stats. This is so we can tell which stats belong to which agent.
The earlier discussed issue is more noticeable in this test, by the way. If you pay close attention you’ll notice the agents walking towards coordinates where berries used to be but aren’t anymore. That shouldn’t be happening! Instead, if a targeted berry gets eaten then they should stop and search for a new one. This will hopefully be fixed next time.
That’s enough for today, though. I’ll see you guys next time in part 6! I will likely fix the above mentioned issues, add more goals / actions and who knows what else. This dumb deer/berry simulation stuff is to help me get used to using GOAP. It also helps with working out the kinks. It wont take long before we’re back to ‘real’ gameplay stuff.