Changing Patrol Logic

Originally guards would have an array of way points individual to each guard.  Whenever a guard reached their destination, that guard would select another way point at random and begin moving to that position.


However this method makes the guards move in a very predictable way, as once they player figures out the way points, they'll know where the guards are going to move to.  I wanted to make this more believable, so I changed their behaviour from a straight "seek" to a "wander" behaviour.  This was an attempt to make the guards move around in a more sporadic way and be harder for the player to predict their movement.

To achieve this I created a wanderRadius around each of the guards and used a method to return a random point from within that radius


This method would create a random point in the scene and test that it is accessible on the NavMesh to allow the agent to move there, if the point was unsuccessful it would call the function again until it found a successful point.  This method would be called whenever the guard reached their destination of after a certain amount of time had passed.  As these nodes are not run on Unity's update method the timer for this is housed within the guard's blackboard within update, once the timer is equal or greater than the wanderTimer the guard would select a new destination.

To visualise the radius the guards would be picking their destination within, I used Unity's OnGizmoDraw function, which allowed me to see how large the guard's "patrol" area is.


However, I was unable to get this behaviour to work correctly due to a few issues, the main two however, were that the agents would keep picking a location not within the bounds of the NavMesh and would begin to walking into the outer walls trying to leave the area, which means that the NavMesh.SamplePosition() function was not working correctly or I have not correctly configured the NavMesh.



The other issues is the guards start walking back and forth on the spot unsure on where they should be going as shown in the GIF below, I am unsure what the cause of this problem is, however, I believe it will be an issue with how the checks are set up to cause the agent to pick a new destination.


I was able to resolve this issue by making sure that I reset the wanderTimer stored in the guardBlackboard at every section that the destination gets changed to a new location as I was resetting a redundant timer I had forgotten to delete, however the issue is still there, but it happens a lot less frequently. 

Although this does not happen all the time, it happens too frequently as does the agents walking into walls, to leave in the project at this stage, so I have decided to revert back to the way point method of patrol locations for the time being, and trying to resolve this issue at a later date with my specialist tutor.