Using the Emerald AI Needs System - Black-Horizon-Studios/Emerald-AI GitHub Wiki
The Emerald AI Needs System Explained
Emerald AI includes a needs system that allows AI to dynamically generate waypoints to resources such as food and water. The Needs System works by efficiently searching for nearby objects of the appropriate layer, when an AI's Current Resource amount reaches 0 (aka it's hungry, thirsty, etc). When this happens, an AI will generate waypoints to the detected resource objects, up to the Max Resource Waypoints amount. When an AI reaches a resource object, users can specify which idle animation will be played based off of the index of their Idle Animation List such as an eating animation. The AI will then refill their resources at a rate of 1 resource per second according to the AI's Wait Time seconds.
After an AI has reached its full limit, it will switch to the Dynamic Wander Type and wander around its new area until its Current Resources reaches 0 again. It will then repeat the process, but most likely getting new resource objects with each time it generates new waypoints. There is also an option for an AI to die if it doesn't get to resources quick enough.
Lastly, there is a Gathering Event that is triggered each time an AI successfully collects a resource. This can be used to run custom code to add items to custom inventories or add values to custom variables.
Using the Emerald AI Needs System
Before using the Emerald AI Needs System, it is advised that you try out the included demo scene to see how it works. This demo scene can be found by searching for the AI Gather (Food, Water, Resources, Etc) System Example scene. Here, you will see a Golem AI wandering around. After its hunger reaches 0, it will search for the specified layer for resources and generate waypoints to the bushes in the scene. After its hunger levels are met, it will begin wandering again.
Step 1
To use the Needs System, search for the included EmeraldAINeedsSystem script and apply it to your AI. This script has a separate editor that modifies some of Emerald AI's settings.
Step 2
The Needs System's Editor will explain what every setting does and is pretty straight forward from this point. Your AI should have been through the initial setup process and have at least 1 Idle animation. The Gather Animation Index determines what idle animation plays when your AI arrives at a resource, which could be animations like collecting, drinking, eating, etc.
For added functionality, users can use Emerald AI's Animation Events such as enabling and disabling items or playing sounds at certain frames of the gathering animation like shown below. For more information on this, see the Animation Event tutorial here: Enable and Disable Interactive Items with Animation Events