So, here’s where we left our “Seek Food” behavior tree (simplified somewhat):
new Sequence( //Browsing new FindClosestTree() new WalkTo(ClosestTree), new Eat(ClosestTree) )
… which was then upgraded to include…
new Selector( //Scavenging new Sequence( new FindClosestCreatureMatch( new Inverter(new IsAlive))), new WalkTo(ClosestMatch), new Eat(ClosestMatch) ), //Browsing new Sequence( new FindClosestTree(), new WalkTo(ClosestTree), new Eat(ClosestTree) ), )
There is a problem here I haven’t quite worked out the best way to solve (the predeliction of creatures to scavange a distant corpse when surrounded by perfectly browsable trees, because of the way the Selector at the top works), but right now I’m working on hunting.
Hunting itself is (at least at the moment) a relatively simply behavior: find something alive, walk over to it, make it not be alive, and eat. The complexities arise not from the plan itself, but from interaction of the other emotions. Fear and anger are the two arbiters of the fight-or-flight responce, and hunting needs to influence these emotions in both the hunter and huntee.
This is where a brand new system comes in:
Ping is the way information is transferred from one creature to another. Eventually, everything from “I’m hunting you” to “I need a mate” to “I require aid” will go through the ping system. It works in a relatively simple manner: creature’s Ping others when they have information that might be of relevance to the other creature.
new Sequence( new Ping(HuntingYou), new RunTo(ClosestMatch), new Ping(KillingYou), new Kill(ClosestMatch) )
Now just because a creature recieves a ping, doesn’t mean they will react to it. Pings are analogous to noise: a creature might not hear it, they might hear it and not be able to locate the source, or they might locate the source but deem it inconsequential. That will all depend on the (yet to be implemented) perception system.
Assuming the huntee does recieve the ping, spots the source of it, and responds, it’s fear and anger will go up. Chances are good one of these will go above their current emotion, and with an urgency threhold of 0, they will react immediately.
This reaction will in turn be accompanied by a ping back to the hunter, letting it know its preys intentions. Now it’s the hunters turn to have an emotional reaction. Seeing a large, violent creature turn to fight might well be enough to amp up its fear and send it running for the hills.
The best part of the ping system is that it’s very CPU-friendly. Rather than continually scanning the area every frame for potential threats, prey just needs to wait for and respond to a single ping. This reduces the number of checks that need to be done and ensures we only need to track relevant information.
So, what’s the end result? I outfitted P. specium with the new Hunt/Flee behaviors and put 250 identical wannabe predators on the map.
The results were interesting. About half chose to flee while the others chased them, based I think on the order in which the pings were sent. I was actually expecting them to get caught in a both-creatures-hunt-both-creatures-flee loop, but it didn’t turn out that way at all.
They didn’t last: I’m not sure they even managed to reproduce. This was at least somewhat thanks to the problem I mentioned earlier: if there were still any creatures in the area, they would hunt them down rather than browsing the vegetation. It was like a zombie apocalypse if the zombies ate other zombies.
All that said, even “zombie” intelligence is a significant step up from their previous AI. Even with their animations not working (I broke them back when I was dismantling the old ai, and haven’t gotten around to fixing them), they now have a sense of purpose and agency that was notably absent before, and I can’t overstate how much of a difference this makes.
Since I wrote this, I’ve made yet another change. Creatures will now have different run/walk speeds: running for maximum meters-per-second, walking for maximum meters-per-calorie. I’ll need to change a variety of formula and perhaps add a few new stats to support this.
In addition to the implications for the simulation, running makes creatures more communicative to the player, since it is only used when hunting or fleeing. To help emphasise this, I’ll probably also adjust their leg animation using the existing Step Size system, to give them a longer gait when running.
For now I’ve just put in a placeholder run speed of 3x walk speed. This results in admittedly freakish sight of predatory Primum specium pointing themselves at an unfortunate victim and sliding across the map at a speed that is just a bit faster than what you’d think they were capable of.
They couldn’t run down a human, but if there were enough of them they might be able to swarm you, especially if you weren’t expecting it. And nobody expects the Primum inquisition.
Still a lot of work to do, but things are starting to take shape.
Next time on The Wriggling Dead: the hordes. Oh god the hordes.