The goal of the project is to make an NPC AI that moves as a squad and can interact with the player, in a real-time action game.
- Smart AIs
- Utility system
- Ally and enemy squad system
- Character classes (Healer, Support...)
The controls are made for keyboard only:
- WASD - Move
- Mouse movements - Aim and move squad
- Left click - Shoot
- Right click - Call for support fire
Launch the exe directly from the archive.
To integrate artificial intelligence in the project, we have to make a decisional model which is the utility system.
The utility system is composed of a list of actions stored in a scriptable object.
An action is composed of methods and a consideration.
Taking an action into account will be evaluated and will give a value between 0 and 1, this value is evaluated from an input and a curve. The input is a method that will return a value, for example, the distance of the player from an enemy. And we will plot a curve against this input that will determine the utility (between 0 and 1) that will be returned by the consideration evaluation.
The utility system will evaluate all the considerations of the actions in order to derive the best action to perform.
When an action is executed it will invoke all the methods of the action. The listed components are all the components attached to the Game Object where the utility system is and the listed methods are all the public methods of the component.
To facilitate the integration of the actions in the utility system we decided to make a custom inspector, for example thanks to this we can list the methods available in the components.
To make a Squad system compatible with different types of controllers ( direct player inputs and NavMesh calculations), we had to create a leader-squad system. When the leader decides to make a move, the rest of the squad must follow this order. The units will not try to reachg the leader directly, but the position where the leader wants to be. This allows us to easily do a patrol system and a unit tracking.
To make the leader send its orders each time it wants to move, we used inheritance and UnityEvents. The leader's orders are linked to its movements updates.
leader.GetComponent<Movement>().OnMoveChange.AddListener(UpdatePositions);
To create an AI team, we had to create a virtual leader (with no collision nor rendering) who cannot die.
To make the units follow the leader's order, the leader must tell the squad (which is a separate GameObject) where it wants to go. Before the squad tells its units where to go, it calculates the correct position that follows its formation rule (which is a manually configured ScriptableObject) for each unit.
To achieve a proper Squad system, we had to create an entity that represents a Squad to manage its own units. The Squad Controller instantiates its units according to its initial formation and number of units. Then, it will be the bridge between the leader and the rest of the squad, through which the leader's orders will pass.
We used the utility system to make specific AI action as healing, coverig or even shooting. We just had to make a consideration function then method(s) function(s), here an example of the healer utility system.
The healer has two actions, shoot at target and heal, shoot at target consideration has lower maximum value, the healing consideration can return a higher value so the healer will in priority heal hurted teammates instead of figthing enemies.
Our system is not limited to only help the player, AI can help each others, a healer can heal anyone but himself, and supports can cover everyone but not supports. The player stays in priority when the unit choose who to help. The targeting choice is managed in the file Assets/Scripts/Units/UnitSquad.cs.
Healer healing - Assets/Scripts/Units/HealerUnit.cs
In the support action, for support units, we use a double method, the shootAtTarget and the cover methods are called so support can cover and shoot at the same time.
Support covering - Assets/Scripts/Units/SupportUnit.cs
You can also find in Assets/Scripts/Agents/AIAgent.cs, the consideration and method for the shooting behaviour of the units and turrets.
Git Lab was used for the versioning during of the development of this project.