Game Development Blog 3

This was our first week after Alpha in our game development course, when we started really doing planning out stuff for beta. My big task for this week was researching and starting to implement our new and improved AI.

Our Programming teacher Tommi had told us that he would dedicate both lessons this week to explaining AI, more specifically A* (pronounced A star). A* is a method of finding the shortest route to the destination for an AI to take.

So I researched A* by searching and reading up on articles. In short, I was very confused, I understood the basic principle behind the method, but it was all very confusing the in how it was actually implemented through code.

When he had his first lesson about pathfinding, he had left us a project where he had a basic layout with a square grid of nodes, the ability to place unpassable objects as well as a start and a finish. He told us to create a line that went from the start to the finish, ignoring the unpassable objects for now. It took me the entire lesson to just figure out what the code did and how to draw a line in the node system.

But to me, that was the most confusing part, and when I got passed how that worked, did all the three variants of basic pathfinding that Tommi told us to try. First, going from start to finish in the X coordinates, and then the Y. Second, simply calculating a line between the start and finish. The third one, which was the hardest, but simultaneously the most interesting, was checking all nodes around your current position, and deciding which one was closest to the finish, and going there. This was repeated until we reached the finish.

From my research earlier, I knew that was the basic principle that was used in A*, which is essentially about checking all nearby tiles for approximate distance left to destination and weighing in the total travel distance required to get to that node. If it was a wall, you would simply ignore that node so that it couldn’t go there. This would get you to your destination and avoiding walls.

, so I really wanted to get that working, and eventually it was working like a charm. The only problem was that it didn’t respect any walls or other obstacles that could come in-between our AI and its destination. So I took a stab at creating an A* system. I knew it would probably not work that great, but I sat an entire afternoon and part night with it, and at the end I had an A* that would search for and optimal route and avoiding obstacles, but it would break if you forced into a corner or just making the wall to big so it had to go backwards. All things considered, I was very happy with that it even did something, but after the second lesson with Tommi where he showcased proper A*, I realized that mine could use some work.

However, he told us that A* is things that second and third years are working with to try and implement, so after hearing that I felt that my version was not too shabby considering that I only had some very basic understanding of Pathfinding. He also told us that we probably shouldn’t try to implement A* in our projects, but I feel that I rather try and have some bugs, instead of just using waypoints, which would be simpler, but also not as enriching for me.

About Erik Lindgren

2014  Programming