AI Navigation Problems - Yashwant Patel

Problem

In Island Defenders we want our AI to go down a lane to reach the core. Ideally the AI should navigate through the lane in a way where they don't cut corners to try and optimize the path they take in order to reach the Island Core. The path finding algorithm is implemented in a way to have the AI reach the destination using the quickest path while keeping obstacles in mind. For most games this would make for good AI, since you want AI to take the most efficient path. In our case we want the AI to always be in the center of the lane even if that path is not the most optimal. This wouldn't affect the user's gameplay physically, but it would seem like an odd behavior to have AI cutting corners in a game like this. For example, if you have a racing game and the AI cuts through the middle of the map in order to go from one point to another it wouldn't make sense. Even though that is the most optimal path in terms of pathfinding it's not the correct path. This is a similar problem we faced.



The green area is the valid walking path for the area and as you can see it goes all the way up to the corners of the valley meaning the AI would cut corners. 

Solution

The first thought was to mess with the parameters of the navmesh in order to make it so only a valid path was generated in the middle of the valleys instead of reaching the edge, but this wouldn't give us the full control we wanted, since not all valleys have the same sized gaps. Another issue with navmesh is we needed to have a separate mesh the AI can walk on (due to how the tower building system will be implemented), but this causes an issue where agents will be slightly floating since the terrain has to be  lower than the mesh that is walkable by the agents because if it's the same height then the navmesh won't generate. Afterwards we stumbled upon a solution which was elegant and exactly what we needed. Splines (you can see them in the picture above, red lines)! We decided to use spline based movement, so the splines would be manually placed and the enemies would have to just use the spline to walk along the path. This gave us the control on the shapes and placement of the splines as well as solving the floating enemies issue. There is a spline movement component that was made that is put on the enemies (theoretically anything can move along the spline) and the component moves the actor along the spline based on the distance along the spline which is incremented every frame based on the speed.

Comments

Popular posts from this blog

UI Polish

Round End Cutscene Implementation