AAAI - Advanced 3rd person shooter AI

Hello everyone,
this is a preview of the exstensive AI project Ive been working on since mid-february 2015. The project is mostly based on documentation from 3rd person shooter games, praised for their, at time of release, state of the art AI! Many of the techniques used can be found in the books Game AI Pro 1 and 2, available on amazon for quite alot of money.

My AI is set up of 3 scripts. BaseEnemyAI.cs, Squad.cs and SpawnSquad.cs. I have not yet tried to optimize for performance, because there is no noticable performance drop yet.

AI Base
This script is only 375 lines (excl. debugging) and controlls the individual AIs.
So far the AI has 5 states planned and 4 and a half implemented:
Patrol - The AI goes from point to point in a predetermined path.
Alert - The AI is alerted by player interaction.
Combat - The AI is prepairing for combat.
Tactical - Tactical decisions made by the AI while fighting the player. The main meat of the AI.
Chase - Not yet implemented // Chase player
Search - Designed in secondary project // Search for the player after a fight

Squad
The squad scripts are what helps the AIs teamwork. I have not really implemented this yet, its only a base that contains a refrence to all AIs in a squad and does a line of sight lookup table. Aprox. 100 lines (incl. debug).

I want to go into a bit more detail for most of the more advanced features:
Vision: The AI performs 3 checks to see wheter or not the player is indeed visible.

  1. Checks if the player is in range of attached spherecollider.
  2. Raycasts to certain bones in the player model, based on bone names. IMAGE: Line of sight rays are debugged in blue. Advanced Line of Sight
  3. Checks if the AI is inside the AIs cameras FoV. Then determines how clearly the AI can see the player through several cones and triangles. IMAGE: Each of the different areas has a different value between 0 and 1, which represents how clearly the AI can see the player. This will be used to change the aiming accuracy and alert state reaction of the AI.Visual cone
  4. Uses a renderTexture to determine if the player is lit up enough. IMAGE: The black cube displays what the AI sees. Darkness detection

Tactics: So far the only tactic implemented is taking cover. This is only possible because of the amazing work of swedish (nordic pride :stuck_out_tongue: ) developer Aron Granberg and his A* Project. The Squad script raycasts from the player position to every single node on the A* pathfinding grid and does a few checks to give each node a tag. The AI then determines which node provides the best cover based on a scoring system, based on the node tags and tactical pathfinding+distance. IMAGE: Blue nodes are hidden behind an object. Pink nodes are fully visible and infront of the player. The green nodes are fully visible but outside the player FoV. Line of Fire

The tactical pathfinding isn’t fully omptimized yet, but it also uses the tags to make the AI avoid the players line of sight and line of fire when moving around.

Search: The search function uses basic extrapolation and random pathfinding in logical directions to guess player movement and search for the player.

Roadmap // TODOs in some order:

  • AI look at player every now and then to confirm player positioning. Improve AIs player positioning awareness in combat.
  • Implement search feature.
  • Implement distraction system ie. throw can to attract AI.
  • Design & implement sound system ie AI hear when player run and not when they sneak.
  • Improve shadow detection system to recognize differences in renderTexture, rather than just bright pixels.
  • Add different scores for different stances. Having cover while you crouch and not while you stand is better than having cover high and low etc.
  • Improve cover system. Take cover where fire can be returned.
  • Implement more tactics like flanking.
  • Implement teamwork.
  • Chase state.
  • Reporting player position.
  • Flanking from multiple directions.
  • Design & implement combat system. ← This is a big one. Gun system is designed but not implemented. No melee system designed.
  • Animations! (Help needed)
  • Tweak tweak tweak.
  • Optimize for performance.

There is more to be done which I don’t have in the back of my head. However my scripts contain over 30 TODOs. Also please post your suggestions below! Much appreciated!

Please keep in mind this is the first AI project I have done. I will make a tutorial series on this whole AI for free once I am finished :slight_smile:

Best regards,

  • Lahzar
1 Like

Update #1:

  • Made a simple lookat function, which looks at the player when the players position is known. Its very basic.
  • Added different pathfinding scores for different stances. I am still perfecting the system so the AI will have different scores for different states aswell, but for now every cover possibility has a fixed score. Turning of the lights and objects in the scene makes it easier to see. (Side by side comparison.) Note how the nodes behind the waist high objects in the middle now are coloured red, while the nodes behind tall cover is coloured orange. The AI will favour a red node. New stance system inengine
  • Added damage interface to AI. The AI can now be damaged and will react to getting hurt.

New todos:
Considering redesigning behaviour system to an option stack/goal stack. Currently the behaviour is controlled by simple if/else statements and a state enum. (If you don’t know what an option stack is, here is a great article: Finite-State Machines: Theory and Implementation | Envato Tuts+)

Next I gotta start working on the combat system. The AI looks so dumb not returning fire.