Game Dev in Progress… Day 22
Hello and good day to you all. This is day 22 of my internship under GameDevHQ. I managed to finish implementing the player movement functionality and moved on to Enemy AI. I was really excited for this section because I love AI and I think it really cool. My expectation for this section was that it was going to be difficult and I was on point… Before going over what I did in Enemy AI, I would like to first go over some of the things I did for Player Movement. Here is a sample of what I did:
As you can see, I animated the player so when they walk, it’ll actually look like they’re walking rather then just sitting still. This was done through using the Animator and some script in order to switch between the idle animation to the walking one. The switching was done by calling the SetBool() function of the Animator class component that was attached to the Player Object. The Animator has a bool parameter that can be set to true or false by using the function above. And to switch, I merely had an if statement that checked if the player reached its destination and then just calling the function if it did.
Moving on to the Enemy AI… This section was difficult but I managed to get about 75% of it done and hopefully tomorrow I can finish it. The section was difficult because its simply just AI. AI had been always difficult to implement and this section was no different. Ill go over some of the problems I faced. One of the first problems is that I couldn’t delete a prefabs children. In the video tutorial, they simply deleted it but because I am working on a newer version of Unity, they changed how prefabs work a bit. So I couldn’t follow the steps they were taking and I had to improvise a bit. Instead of deleting the prefabs, I merely just deactivated so they don’t show up. Of course, this isn’t a good solution but for now I can worry about that later.
Another problem I faced is actually coding movement pattern of the Guards. Particularly, I had a specific problem where the guards would rotate rapidly around the two end points of the walk pattern that I setup. I realized this happened because I turned off Auto Break. If auto break is turned off it would stop by deaccelerating until it reached its the point. But because I wanted it to precisely stop at that point, it can never do that. This is because the acceleration and speed will make it overshoot the point. Then because it’s not on the point it will accelerate again and overshoot again… *Sigh* Luckily the solution is simple.
The NavMeshAgent has a parameter called stoppingdistance. The way stoppingdistance works is that when you give it a number (most likely a floating point number), it will create a circle/sphere around that point with a radius of the number that you gave it. This circle will tell the NavMeshAgent that it is acceptable to stop within this circle. In my game, I gave it a number of 0.5 and it creates a circle around the point that it has to stop at. So even if the guard overshoots the stop point, as long as its within the circle, it’ll stop. Here is what I have so far:
Overall, I have learned a lot about designing simple game AI. Also I would like to point how cool NavMeshAgent is. I don’t have to code how the guard will move, I just need to give NavMeshAgent a position that I want them to move and it will the moving for me. I plan to finish up this section and then work my towards the next one tomorrow. Until then, thank you for reading!
_
Cristian Aspacio