Week 7 AI pathfinding.
- ef1998
- Nov 12, 2020
- 3 min read
A*
I decided that I needed a pathfinding system because if the player is being chased and the enemy AI loses the player, the AI would need to find a path back to whatever location they are patrolling, and so the problem comes in preventing the AI from walking into walls. After looking around online, I came across a book in the Abertay Library called AI for Game Developers that talked about a pathfinding algorithm called A*. I weighed up my options on whether I should risk trying to implement this thing I've never done before and have no experience in vs replacing my movement system with Navmesh and in the end I took the risk and it payed off really well. It took about 230 lines of code for the algorithm class along with 2 other classes and I became worried this wouldn't work as time went on, but when it finally did I was overjoyed. Now I can have pathfinding and my own movement systems. I made a video explaining the algorithm here for other students in case they were interested.
I had some issues After I implemented A* for preventing the AI from walking into walls when they turned corners, because the book doesn't address that so way I fixed it was to have the AI walk in Manhattan distance when turning a corner.
Grid and Nodes
the biggest problem I had was defining a grid for my nodes. making the grid for any normal circumstance wasn't a problem but adapting it to the room orientations was. I decided to make it work across the XZ plane, but the way I initially made it was working across the global XZ plane, which is a problem if your rooms are rotated at different orientations. I instead opted to use a bit of vector math to define my grid where the local right vector and local front vector of the grid is multiplied by the cell size to determine real world locations of grid locations. One of the biggest problems was actually getting it to work with the room system as I had some ordering issues and I became worried that I would have to completely redesign my grid system, but luckily after some trial and error I fixed the issue by placing the initialisation function in the OnAwake() function.
Level design sketch
Most of my time has been dedicated towards the pathfinding system but I did manage to get out 1 room design just before the week ended and I also managed to implement it in my build. Now I will be fully dedicated towards making new designs so I can properly playtest this with some fellow students.

AI tweaks
I've tweaked the AI a little bit because I felt that the turning and waiting was a little slow and so I made them a little bit faster to make the AI seem a little more believable in terms of its "humanity". I've still got many tweaks to go but its a good start for now. I also think that I might increase the view cone as it feels too easy to pass the AI, but I am nearly running into them meaning that the AI behaviours probably feel about right.
Build Video
Currently the build is going swimmingly well. A little more and I will finally be able to test this out on some students.





Comments