Greetings ladies, gentlemen and Unity geniuses!

Background story: I have in my free time been working on an AI for a tactical stealth action game. The AI works marvelously so far and its about 400 lines (excl. variables and attributes and such), but I still havent added the main meat, how it reacts to combat. After doing a normal amount of research, about a days worth, I could only find this: http://www.cgf-ai.com/docs/straatman_remco_killzone_ai.pdf Its fantastically detailed, but I have run into some problems. Things start to get impossible whitout A* after the Tactical Pathfinding section.

Relevant info: I am using the navmesh pathfinding system builtinto Unity, NOT an A* algorithm. The only places the AI can take cover are on predetermined locations. I am thinking about converting to A*, but I dont really know how it works. I have done very little research on it. All tactical calculations are made constantly in the background in coroutines, while purely mathematical calculations are done in threads. I am basing most of how it reacts to combat on the documentation for the AI of the first Killzone game, found here: http://www.cgf-ai.com/docs/straatman_remco_killzone_ai.pdf

Problem 1 - Dynamic Cover: With the bultin NavMesh system I have no idea how to dynamically find cover. The problem with this is time. Its easy to set up, but it takes a VERY LONG time to set up, if I am to expand out of my testing map into a proper level. With A* the AI can simply consider every single path point like in the Killzone document, but isnât that very resource intensive? The Killzone document mentions lookup tables, but I donât know what this is? I am simply using if/else statements and vector maths which might be more accurate than they need to beâŚ But say a car drives past a shootout on a road, and someone kills the driver or shoots out all the tires, and the car just sits there in the open. In Unity you can simply attach a navmesh obstacle to the car, and the AI knows its there. How does one do that in A*? But Unity canât take advantage of this, unless you place empty gameobjects all around the car. Can you do that dynamically? I know you can do it in A*, but how?

Problem 2 - Wall Hugging: The only places the AI can take cover are on predetermined locations (the AI finds all (empty) gameobjects tagged âcoverâ), and naturally Ive set these locations near walls, but its still the same problem as problem 1; time. I dont know how you would do this in A* either?

The rest of the problems with the AI are easy to solve if I can solve problem 1. But thinking about it logically, it seems the only way to go is to convert the AI to A*. So thats the last problem.
Problem 3 - Converting to A*: I havenât started researching this in detail yet, but it seems like an awful amount of work. I am not going to buy anything, partly because it feels like cheating, partly because I want to put this AI on the asset store, possibly for free but stillâŚ So converting to A*, will this be difficult? Will I need to rewrite anything in my scripts? Should I attempt to make it from scratch, if so: where do I even begin? If not, will I still be allowed to publish the AI on the assetstore, considering most A* algorithms you can download are already on the assetstore with a license?

I know Im not very good at explaining, so if there is something you didnât understand, just ask, Iâll try my best to explain better! - Lahzar

First of all, A* is a general algorithm for pathfinding. Iâm pretty sure that Unityâs navmesh system uses A* under the hood to do itâs pathfinding.

Thereâs also something called âthe A* projectâ, which is the most popular third-party alternative to Unityâs Navmesh. It exists in a free and a premium version. There is, of course, a feature split.

A lookup table is simply a table you look stuff up in. The most common way to use this is to do some expensive calculations before-hand. In your case, you could take a bunch of points on the navmesh, and calculate the closest cover point from each of those. Then, you store that data. When your enemies needs to find cover, they look up the closest point in that table instead of calculating it themselves.

Unityâs NavMesh also has a function named FindClosestEdge, which finds the closest edge of the navmesh, which is probably where you want your enemies to be when taking cover.

Thatâs a bit of information, hope it helps!

1 Like

Okay, so after some research I have a decent understanding of A*, and I know that like you said, @Baste , unity uses some form of A* under the hood. This would all be very easy if I could simply access its nodes! Does anyone know a way to do this? I saw someone saying that .SamplePosition is something like this, but I havenât looked into it. I am still researching .FindClosestEdge aswell. I simply dont understand it quite yet.

I wonât actually need a fully fledged A* system, only the grid creation, so something like the A* project seems a little bit excessive, doesnât it? Ofcourse, the A* project is a viable solution, but it seems a bit excessive, and the free version doesnât quite cut it for this particular case, im afraid.

Lookup tables - Sounds great! Probably wonât be focusing on that to begin with, though. Definently when Im nearly finished with it all, and Im optimizing everything, but for now I just want it up and running!

Itâs generally a huge problem with the built-in NavMesh that users donât have any access to the data whatsoever. You canât access the navmesh, you canât construct it on your own, you canât modify it, nothing. You have to mark things as static, press âbuildâ, tweak the settings, and hope dearly that it fits your need.

That doesnât really help you, but thatâs how things are. If you want to expand on a system, and be serious about it, Iâd go with A* pro since you get source for that.

Are you talking about the Aron Granberg A* project?
http://arongranberg.com/astar/

If so, Iâll toss in my vote at how good it is. I have the pro version and itâs very useful.

Just buying A* pro seems like the best and easiest solution. But I am a mere student and I donât have that kind of money to spend on something that might not âpay offâ financially within the forseable future

So here is what Im thinking: I need to find a way to generate a grid like the A* Project Pro does it. Go up really high, and linecast down or something, the problem isnât really generating a grid, its finding a way to connect the generated nodes automatically. Still havenât found anything useful on the subject, thought.

Doing A* on your own through a network of nodes is still really slow. You should read up on what a navmesh does, but the basic idea is to create an as simple as possible mesh that covers the ground youâre pathfinding over, and then use A* over the vertices of that mesh.

It reduces the number of pathfinding iterations massively, and allows for smoother movement as the algorithm can freely move objects wherever it wants within the triangles of the mesh.

Iâve done some more research, and I found out about the books Game AI Pro 1 and 2. They seems really usefull on the subject of AI. I will buy them as soon as I can, but they are really expensive, about \$70 USD each! The books contains chapters on tactical pathfinding using navmeshes aswell.

I got myself the Aron Granberg A* Project Pro aswell. And I am really glad. Getting the pro edition might have saved me years of trying to make it myself! I am in the process of cleaning up the scripts I have and converting them to use the A* Project. So I am remaking my AI scripts into 1, instead of one that controlls movement and one that controlls its vision.

After Ive done that Ill start making the tactics that are described in the killzone document. Hopefully I wont run into any more problems. When Im done with that Ill implement teamwork, and then I donât know where to go from there.

Since I now am relying on the pro version of the A* project to move my AI and to use a majority of tactics, the AI I am making will not be on the Asset Store, but Iâll definently make a tutorial on it or something.

Thank you all for your help and suggestions!

• Lahzar