Game Development Reference
In-Depth Information
Our root node is a parallel type, so the character is always trying to detect gold, but it
still ignores it while traveling. This is because our move node will keep running until
it hits its destination, and even if it sees something, it is not interrupted until it gets
there. To fix this, delete the move node underneath ChooseRandomSpot Custom
Action . Then, change ChooseRandomAction to the code shown in the following
screenshot:
This is a big change, so let's discuss what is going on. The Start method is the
same as before: store a random position to move to in memory. However, our action
method is different. The first thing it does is it queries the memory for gold. If we have
gold, we don't need to keep moving to our target, so we return failure. Then, we get
our moveTarget variable out of memory and check the position of the Body vari-
able of our AI. If it is within one unit of the goal, we say that this is close enough and
return success. Finally, if we don't have gold and aren't close to moveTarget , we
call on the AI's motor system to move to the target and keep updating it by returning
the running state.
Note
With this update, we could have used a regular class variable to store moveTar-
get , but we keep it in memory to keep things consistent.
If you run the demo now, we will see the ships moving around as new gold appears
in more expected ways, as shown in the following screenshot:
Search WWH ::




Custom Search