- Home /
How to make a modular enemy AI system ?(please read the description before skipping)
So the question is kinda broad, but the specific thing I wanna know is this :
I have a base Enemy class, and EnemySniper, EnemyPistol etc inheriting from it.
and I use FSM to manage the states. Now the thing is I want my enemies to have different behaviours in states, like enemyPatrol to be smoking in idle state, but enemySniper to be whistling for example. I did this by implementing ISmoke and IWhistle interfaces to child enemy classes, so when I call an Idle method from Base Enemy class, In the child class it will override it to be whistling etc.
Now my problem is that, I dont want all my enemyPistols to whistle in idle state, or snipers to smoke. I wanna have variety between all of them, some enemyPistols can would smoke, some would whistle, some would talk etc. I dont know how to do this with good code, anybody can give me an idea on how to achieve this?
If this is a game-like app and your ai agents has some kind of visual representation (animated 3d model or 2d sprites) then don't hard-code idle behaviours as interfaces. Just expose some kind of idle_animations
array field in the inspector and let animation-authoring customize it for each enemy type.
Answer by logicandchaos · May 10, 2021 at 12:03 PM
I use a fuzzy pattern matching state machine, where actions are defined in scriptable objects and characters have a list of Acts that all have conditions. The finite state machine selects the best fit action for the current situation, it is based on the left4dead bark system. Here is the asset: https://assetstore.unity.com/packages/tools/ai/dynamic-behaviour-187865
Your answer

Follow this Question
Related Questions
Interaction script 2 Answers
"Re-usable" enemy behaviour? 2 Answers
How to make a List that can store anything that implements an interface? 4 Answers
C# inheritance advice 2 Answers
Need to inherit from EventArgs AND ScriptableObject 1 Answer