Monday, 1 February 2016

Coding - Search Iteration - John Howard

Task

To update and fix the search function to work in a more logical manner.

Overview

Fixing the search function was the next most important area of code for now. I decided to approach this similarly as the patrol was done. Using coroutines that are called within the transitional states within the core state machine. By doing it like this I can again take the code through a step a time and only call the parts that are needed. Firstly the movement to the last sighting has to be completed first and I simply do this by calling a void for one frame that sets the nav.destination to the last sighting transform. Then the search routine is started. The corotuine cannot move through its next destination setter unless the AI is within a certain distance of its current destination. And before even this I call a Randon.range which tells the rotuine how many times to run before returning to patrolling. I feel this is a much more reliable way of timing the routine rather than a timer+1 per frame and also a less messy one. The new point is simply generated by a Random.range of z and x added to the current transform of the AI. This point is then fed into the nav.destination again. This repeats for the amount of time set in the initial time caller as mentioned earlier.
Search Code

Thoughts

This works a lot better than the original setup and whilst it takes a lot of code from the initial one it calls it in a more logical format and allows a better ease of control to a developer changing values. I am quite happy with how this code turned out and shall most likely leave this iteration as is for now. 

No comments:

Post a Comment