Conversations

To make the guards more believable, as they are patrolling around the scene, should they cross paths with another guard, they will stop to have a conversation with them.  This helps break up the predictability of the guard's patrol, as once they have finished with their conversation they may end up travelling in a different direction to what they had originally started upon finding a new patrol destination.  It will also start to lock off paths that the player can travel down as there will be at least two guards standing in their way.

The converse path in the tree is part of the IDLE SelectorNode and takes priority over the patrol nodes.  shouldConverse is a SequenceNode that has three children;


Attempt Conversation
This node is used as a conditional check that ensures that the agent hasn't recently had a conversation.  This stops the guards from being in constant conversations either with another guard that walks past or reenters conversation with the previous guard.  If the guard has recently had a conversation the node will fail and cause the parent node to fail, which will result in the guard carrying on their patrol.

This node will will also check if the guard they are passing has recently had a conversation or is currently in a conversation, this will also cause the parent node to fail, causing both guards to continue with their current actions.

Is Friendly Nearby
This node will check if there are any guards within range that the guard will be able to converse with, as long as they have not recently conversed.  Once this node enters its update stage, it will check the distance between all the guards, if any are within the minimum distance required to start a conversation they will set themselves to having tried a conversation and set the other guard as their conversation target.

If the other guard is in a conversation, the third guard will set himself to having tried to converse but carry on his patrol.  I have also implemented a check to ensure that the guard doesn't try and check for himself, if the for loop gets to the guard, then the loop will continue and jump to the next iteration.


Should Converse
If the agent's behaviour tree passes a success on the previous two nodes, then the two guards will successfully have a conversation.  On the update of this node, the guard's movement will be stopped, and the two guards will look at each other to simulate conversation and their states will be set to conversing.  

Then a Co-Routine will be started within the guard's blackboards that will keep the guards in a conversation for X amount of seconds.  Once the Co-Routine has finished the guard's will be reset to continue patrolling their areas.  

However, currently only one of the guards will leave the conversation, leaving the other guard just standing there for a few more frames before he too will carry on, this is demonstrated in the GIF below.


I am unsure what is causing this problem as the guards use the same Behaviour Tree framework, however I would assume it's an issue with how each node's update is called and will be something I will discuss with my specialist tutor to work towards a resolution.