Day 4
Keep On Movin
Man what a day!
We achieved quite a bit but we really would have liked to have done more. Of course nothing ever goes as planned but we got there in the end...
Our main focus for day 4 was navigation for the AI and adding all the modifiers that go with it so that he goes to his main objective but as his paranoia goes up the chance to make some less efficient decisions goes up too. On top of this we wanted to add the player in as a factor for the AI to get away from.
I apologize that this is more of a technical and somewhat boring post dealing with what we did and how we did it in a little more detail.
With our basic navigation setup so that he would head towards his objective we added nodes (empty game objects) where we think his decisions would be made so for instance at a fork in the road. He would then check to distance(path distance not straight line) of his current waypoint and the waypoint he wants to go to and add the distance from that waypoint to the goal waypoint. All the waypoints in range were put into a dictionary - the waypoint object and the total distance - and sorted from low to high. Phew quite a mouthful. Basically it looks at all the possible nodes he could go to in range and sorts them from shortest to longest.
To start out we just took the first in the list and had him go there. That was our first milestone and it worked great. From there we tweaked it a little, increasing the range to search for nodes and also adding a buffer so he searches for and chooses his next node before he gets to the existing one that way he wouldn't always walk to the middle of an intersection before turning.
So far so good we had a basic system up and running and he was going where he needed to.
Next we needed to add the paranoia element. So as his paranoia goes up the greater chance of him taking a route that isn't as efficient. To do this we needed to take all the nodes in the list and calculate a percentage for the chance that they would take that route based on their distance, the shorter the distance to the goal the higher the percentage that they would choose that route. This alone is a pretty good system for adding some random behavior to the AI instead of him always taking and knowing the best route available to him. However this doesn't activate unless paranoia is greater than 0. The tricky part is using those percentages and then modifying them. The way we did random was to start with the first one and add their chance to a separate number starting from 0 until all of the nodes were added, the last one being 1. then we would get a random number between 0 and 1. Then using that number we would check which of the nodes percentages are closer and that would be the one chosen.
OK great we have some random decision making on the next node to go to. Next we need to modify those percentages as the AI gets more paranoid. So to do this we took the deviation from the mean and divided it by the paranoia modifier. then we would add that to the mean to get the new percentage. What this does is bring everything closer to the mean so that at max paranoia he would have equal chance to make a bad decision than a good one.
From there we added the player modifier so that the AI would try and go to his objective but also try and stay away from the player. This activates when the paranoia is at 1 indicating that he's not paranoid anymore and that there is actually someone chasing him. Now to make nodes less desirable based on how close the player is to that node we just divided the total distance (current node + next node + goal node) by the distance that the player is from the node. On top of this we also added a threat modifier which is based on how close the player is to the AI within their threat range. We then turned that into a number from 0 to 1 so that if the player is at the edge of the threat range it wouldn't have much effect on the percentage chance that a node is picked but if they are it would effect it greatly. In our tests if the player was close to the AI and the player was close to one node and the AI at equal distance from 2 nodes the AI would only have around 10% chance if not less to go to the one the player is standing at. On top of this we added a ban list for any node that has already been traveled to, that way the AI won't double back and will stop them running between 2 nodes which happened more often than we were comfortable with... There were quite a few bugs as expected one really annoying one was that using the Contains function for a list (checking to see if a node is in the ban list) is a bit finicky when it comes to game objects so we had to change to using the name of the node rather than the object itself, This was ok since we already used what we needed from the object.
Man, when we got that to work it felt amazing! seeing the AI head towards their objective but turn the other way if the player was close was really cool.
Now we need to adjust and tweak a few things. for instance it might be better that if a player is at a node then there should be almost no chance for them to go there( we still want some so that on some off chance the AI will try to charge the player thinking they can get past them or through them :D.
That was a long day and we had some headaches forming so we headed to bed straight after and left this blog post to the morning. It was well worth it but we would have liked to get it done sooner as we're running out of time.
I've attached some pictures of the basic level and lighting so far. still a lot to do but at least we have some visuals
Up Next:
- Add interactables for the AI to slow the player down ( also used by the player but in a different way) We're going to start with some barrels that can be knocked into the path and if the player collides with them then it'll slow down their movement for a second or 3. Moofle will be working on this.
- Additionally I'm going to be working on improving the movement adding some nicer animations with root motion as well as adding jumping onto higher platforms and vaulting over smaller ones if I have time.
Along with all these we sometimes take breaks to work on other things like level design and UI.
Thanks for reading and I hope you're enjoying the journey along with us, until next time, have a good day!
↧