Hi! It’s Dennis here again that has been working on the artificial intelligence. The AI has become much smarter since I first talked about it so I’ve made some good progress. I also managed to fix the problems mentioned in my last post.
Problems solved
The first problem was that when the AI was supposed to slowly rotate to look around, the result of the rotation was seen when it was completed. This happened because I rotated it with a while-loop. I couldn’t use Timeline in Behavior Tree Tasks, so I made a custom event that handles the rotation in a normal blueprint for the AI character. This event is called from the Behavior Tree task so everything is fine now.
The other problem was that the AI would skip the first search node when searching a room. This was, as expected, a very stupid miss that I did. When setting the path node to go to, it would first check if the desired path node was room node and select the rooms first search node. I never did anything to stop it from continue checking what the desired path node was, so right after the first node was selected the next one was selected too. This was easy to fix, instead of having a sequence for all node checks, it will only check the next node type if the cast to the type was failed.
Detecting and attacking the player
A patrolling AI obviously need to be able to detect threats. I used the Pawn Sensing component built in the engine so the AI can be able to both see and hear other pawns. In this game there will only be two pawns, the player and the enemy, so there is no need to check if it sees a player. When it sees the player the Behavior Tree will abort the branch for patrolling and run the other for chasing the player. When it’s close enough to the player it will stop, do an attack and begin chasing again. I also made a finishing blow attack for killing the player. When the player dies the enemy will play another animation that kills the player. The player is supposed to be locked at that state but it is not implemented yet since I had to program some of that in the character controller which is Jonathans area. He has been sick so I couldn’t implement it without him.
When chasing the player, it will always register if the player is seen and where it’s seeing it. So when the player is out of sight it will continue chasing the player for a certain amount of time until it no longer knows where the player is. The AI will then go to the last point where it saw the player and look around the spot. Then it will continue patrolling at the nearest room node from the position where it last saw the player.
When hearing a noise, The AI will behave the same way as when loosing track of the player. It will stop patrolling, go to the point where it heard the noise, look around and then continue patrolling at the nearest room.
Searching in hiding spots and adapting
I added hiding spots as part of the patrolling of the AI. These hiding spots will be objects that the player will be able to interact with in order to hide inside, under or behind. When the AI was searched the room like I have described before, it will the search in hiding spots. This is the part where the AI will learn from the player and adapt.
If the AI hasn’t found the player before, it will choose a hiding spot at random. It will walk up to a hiding spot and play an animation for looking in the spot. The animation will depend on the type of hiding spot and if the player hides inside it. If the player wasn’t found the AI will be done searching the room. This could prove to be too easy on the player, so I might add a system where we can set how many hiding spots will be searched in each room. It could also be a random range. However, if the player actually is found, the type of the hiding spot will be stored in the blackboard of the AI. Right now there is no animation for finding the player and the player can’t actually hide yet, but he system for the AI is there. The AI is supposed to drag the player out, hit it and chase it like it usually does.
When the player has been found in a hiding spot, the AI will choose what spot to search based on the type of spot the player was found in. If the player was found inside a locker, the AI will then be focusing on searching lockers. When searching a room, it will search all lockers in that room. If the player hasn’t been found after a certain amounts of search attempts, the AI will go back to search spots at random.
What’s next?
The player will obviously need to be able to hide, so I will cooperate with Jonathan since I know how the hiding spots work and what needs to be done. I will also work with him on that part with the AI killing the player but that should go fast. I should also make the AI be able to open doors, that’s a good skill to have.
Another thing that I would like to do is to give the AI a real humanoid skeletal mesh. That red smiling cylinder can be very creepy and all, but it looks stupid and we’re almost halfway through development so it need to look good soon.
It’s time for Christmas soon so I would like to wish you a merry Christmas and a happy new year! See you next time in 2018!
0 comments