A threaded, all-in-one solution for realistic mood-driven animal agent behaviour in Unity.
This package uses finite state machines to mimic animalistic actions depending on mood which is driven by vital and environmental factors.
Get more details at http://www.itsMilkid.com
Features:
-Multi-threaded for optimized performance
-Included pooling and spawner
-Three different agent behavior modes (Agressive,Passive,Defensive)
-Four different agent moods (Satisfied, Tired, Hungry, Hurt)
-Eight different agent behaviors (Idle,Rest,Eat,Wander,Flee,Chase,Attack,Dead)
-Hightly costumizable to fit every need
-Adjustable for every kind of animal
-Programmatically calculated waypoints
-Optional static and dynamic wandering behavior
-Supports Mechanim Animation System
-Easy Implementation
-Detailed Documentation
Description:
Milkid Animal Agent AI uses interfaces as behavior states. I’ve almost completely avoided the usage of colliders for distance checks as Unity colliders always check the entire scene. I’ve tested out quite a lot of different methods to reach as little as possible computational effort when using it. I’ve decided to completely rely on mathematical distance checks that are running in a different thread instead of using the physics engine for that. Therefore if you want your agents to attack Players, you’ll have to use the TrackableObjects class – this will be explained very detailed in the documentation. This asset also comes with a built-in pooling and spawning solution, which is easy to adjust to your likings.
Behaviour Pattern:
To achieve realistic behavior I had to make sure that there are no long periods in which the agent stands still and does nothing, that’s how I came up with the idea of having a base cycle of behaviors which extends itself upon possibility.
Here, the base cycle is built from the wander and idle state. This means: If the agent is currently in its idle state and no other behavior is triggered by the given conditions and a certain amount of time has passed the agent will switch into its wander state, where it remains for however long it takes to pass the given amount of randomly generated waypoints. And again, if that behavior isn’t interrupted by any other triggered behaviors, the cycle will go back to its idle state.
However, if f.E. the agent got hungry and found some food while wandering, it will exit wandering and switch to its eat state and as soon as this action is finished, it will go back to its usual base cycle.
Threaded Agent Awareness:
As mentioned earlier – I tried to stay away from excessive collider distance checks as they suck up performance. Instead, I decided to make use of an observer pattern and make every agent trackable. The tracking actually stores the current position of the objects, it doesn’t update itself, instead, the agent updates his position in the tracking whenever it moves. The fact that I basically made up my own trackable object opened the door for multi-threading, as you can’t use Unity engine variables for threading. What happens under the hood is that the agents request to look for a target, those requests get queued and then processed after each other in another thread and return either a target or null to the requesting agent.
Asset Store Link
Feel free to use this thread for discussions, questions and suggestions.