So, I’ve been working on Spamocalypse on-off over the last while, and I’ve got a basic framework for the AI in place. At the moment, I’ve only got the basic dumb bots able to attack, but that’s on hiatus until I get the AI to be able to move close enough to a suspected player. That’s proving to be harder than expected, but I think I’ve got it now.
One of my problems was that the alert time isn’t incrementing properly. It does work if I set it to constantly increase while they are searching, but that results in them getting bored before they get to the endpoint. What I’d like is for their alert time to increase only if they have nothing else to do: if they still have a path to a possible player position, the time spent travelling along that path shouldn’t count. And if there’s a direct line to their new position, why bother searching for a path in the first place?
Running the pathfinding code for five or six bots on startup caused an unacceptable drop in framerate, so I’ve tried to rework the pathfinding code. Instead of doing a while loop that lasts until they find their destination, they will now do a fixed-depth search of 50 nodes. I tried this during my Master’s project, and it didn’t work out as planned, but I suspect that was due to the level layout and resetting the open list too frequently. In real life, most people would not map out and remember every step along a path, so limiting the search depth makes some sense. However, this hasn’t worked, so I’ve gone back to using the while loop – as that will at least work.
I’ve also adjusted the method to set the units’ destinations: it now performs a raycast to make sure they have a direct line to their destination. If this returns false, then they assume that there are no obstacles within 20 metres of them and their destination, and they will just move in a direct line. If that fails, whether due to an obstacle being in the way or the destination just being too far away, they search for a path. If they get within their optimal attack range from the decoy/Sockpuppet, they stop and then the alert time increments. I’ve done some quick tests, and it seems to work well enough for me to start planning other mechanisms.