Squad AI

So you’ve probably played a game featuring the subject in the title, but how many of you here would happen to know how to implement that in C# using Unity’s API?

Obviously pathfinding and then commands in this case are very difficult subjects, but does anyone know a quick and dirty way to do it to just build a proof of concept? It’s a First Person Shooter with two squadmates and the biggest thing is to get them to follow and attack on your behalf.

General tips or generic code are greatly appreciated.
Thank you!

You can use unity’s built in nav system. It has limitations because its nav mesh is baked so you cant really edit the terrain. this is good for games with a static environment. Your right pathfinding is fairly advanced and its even harder to optimise it so your game runs at a reasonable frame rate. The commands required would be relatively simple compared to pathfinding, basically enums, coroutines and switch statements would be the foundation for a command structure.

As @Craig8726 suggested, Unity has a built-in navigation system. See NavMesh and NavMeshAgent. This system essentially enables your AIs to be aware of the environment and enable them to navigate from a starting point A to a destination B. So you can use this system to make them follow the player by finding the shortest path and avoid obstacles and such.

For defining how your AIs cooperate with the player, I suggest to learn about Behaviour Tree. It’s a modern AI technique which allows you to describe how the AIs behave in a manageable way.

Have a look at Panda BT (www.pandabehaviour.com), it’s a scripting framework based on Behaviour Tree that I am maintaining. The package contains various examples, including a third person shooter that use NavMesh and implements behaviour such as patrol-chase-attack and cover. However, there is no example of cooperation with the player. Though it would be easy to implement such behaviour. If you are interested by using this package, I could help by providing a cooperation example.