New Engage, Wander and patrol Behaviours
In addition to the patrol branch of my behaviour tree (BT) I have created another branch that handles the the control of flow once the player has been spotted.
At the root node I have added another child selector which will select a behaviour based on if that current guard can see the player, or if the player has been seen by another guard. If the player has been sighted by this guard, the tree will check the state of the player, if they are in combat (can see the player) they will update their speed and enter another selector.
The Shoot or Move selector will decide if the player is within a certain range, if the player is within this range, the guard will "shoot" and kill the player, causing them to respawn back at the start location and the global blackboard will reset the guards states back to idle. Although once the player is respawned two guards remain in the alerted state. This is something I will look into and hope to resolve before the project deadline.
If the agent is not within range of the player to "shoot" them, the sequence will fail and will start the movement behaviour, which will aim to move the agent closer to the player until the player is either within range or no longer in sight.
If the agent is not within range of the player to "shoot" them, the sequence will fail and will start the movement behaviour, which will aim to move the agent closer to the player until the player is either within range or no longer in sight.
If the player is not in sight, but has been spotted the guards will access the player's last known location (which will be updated if the player is still in another agents sight) and set up a search radius around that location creating a wander location. Guards will wonder around this location for X amount of seconds before returning to their alerted patrol state. Below is the first iteration of the wander behaviour and another with multiple agents running the behaviour exploring the player's last know position.
Agents also now have two different patrol types they have the original idle patrol, but they also have an alerted patrol where after searching an area for the player, they will return to their original patrol routes, but will do so at increased speeds as if they're still searching for the player and alert. After X amount of seconds they will revert back to an idle state and patrol.
While implementing the new behaviours the line of sight (LoS) functionality broke, where the guard's origin for the raycast would fall through the floor and stop them from noticing where the player is. To fix this I had to recalculate how the field of view worked.