Uploaded August 2023 | Updated September 2026, 1 hour ago
Learn how you can implement Enemy AI with a Finite State Machine. This is a full implementation using Unity Hierarchical State Machine (Unity HFSM), a code-driven state machine framework for Unity.
🔶 ALL THINGS LlamAcademy now available at: https://llamacademy.dev/support including latest tutorials, courses, ways to support, and more! Check it out 🙂
👨💻 Get the FULL FREE PROJECT on GitHub: github.com/llamacademy/ai-series-part-47
🏷️Save 25% on the ultimate C# IDE: JetBrains Rider with code LLAMACADEMY: jetbrains.com/store/?section=personal&billing=yearly
📚 Resources:
🟠 Unity HFSM: github.com/Inspiaaa/UnityHFSM
🟠 This super cool Llama: assetstore.unity.com/packages/3d/characters/animals/mammals/llama-quirky-series-178234?aid=1101l9QvC
🟠 Unity Particle Pack (free): assetstore.unity.com/packages/vfx/particles/particle-pack-127325?aid=1101l9QvC
🟠 AI Series 44 (Movement Prediction): youtu.be/1Jkg8cKLsC0
🟠 Damage System: youtu.be/6yvUmSxlGQo
🟠 Unity 2021 Object Pooling API: youtube.com/watch?v=zyzqA_CPz2E
🟠 Comparison of AI Behavior Frameworks: youtu.be/CZvfuNfdc1M
Some links may be affiliate links, which at no additional cost to you, gives me a small portion of the purchase.
Chapters:
00:00 Topic Introduction
00:35 Unity HFSM Installation
01:25 What to Expect & High Level Design
02:50 FSM Design in Animator
06:22 Unity HFSM Key Classes - StateBase.cs, State.cs, StateMachine.cs
07:26 EnemyStateBase.cs Introduction
07:48 EnemyState.cs - Defines all possible states
08:00 StateEvent.cs - Defines all possible events
08:10 Enemy.cs - Set up State Machine with all states
09:58 EnemyStateBase.cs - Base State for all Enemy State Behaviors
11:45 IdleState.cs
12:18 ChaseState.cs
13:31 SpitState.cs & Spit.cs
14:45 AttackState.cs
15:22 BounceState.cs
15:34 RollState.cs
16:15 Add References & Update State Constructors - Enemy.cs
17:49 Detect Player Within Different Ranges - PlayerSensor.cs
18:18 Use Player Sensors - Enemy.cs
19:10 Add Chase/Idle Transitions - Enemy.cs
20:35 Add Roll Transitions - Enemy.cs
21:54 Detect Collisions while Rolling - RollImpactSensor.cs
23:16 Add Transitions to Other Attacks - Enemy.cs
23:58 Set up Objects in Unity Editor & Demo
25:12 Final Thoughts & Support LlamAcademy
Learn how you can implement Enemy AI with a Finite State Machine. This is a full implementation using Unity Hierarchical State Machine (Unity HFSM), a code-driven state machine framework for Unity.
🔶 ALL THINGS LlamAcademy now available at: https://llamacademy.dev/support including latest tutorials, courses, ways to support, and more! Check it out 🙂
👨💻 Get the FULL FREE PROJECT on GitHub: github.com/llamacademy/ai-series-part-47
🏷️Save 25% on the ultimate C# IDE: JetBrains Rider with code LLAMACADEMY: jetbrains.com/store/?section=personal&billing=yearly
📚 Resources:
🟠 Unity HFSM: github.com/Inspiaaa/UnityHFSM
🟠 This super cool Llama: assetstore.unity.com/packages/3d/characters/animals/mammals/llama-quirky-series-178234?aid=1101l9QvC
🟠 Unity Particle Pack (free): assetstore.unity.com/packages/vfx/particles/particle-pack-127325?aid=1101l9QvC
🟠 AI Series 44 (Movement Prediction): youtu.be/1Jkg8cKLsC0
🟠 Damage System: youtu.be/6yvUmSxlGQo
🟠 Unity 2021 Object Pooling API: youtube.com/watch?v=zyzqA_CPz2E
🟠 Comparison of AI Behavior Frameworks: youtu.be/CZvfuNfdc1M
Some links may be affiliate links, which at no additional cost to you, gives me a small portion of the purchase.
Chapters:
00:00 Topic Introduction
00:35 Unity HFSM Installation
01:25 What to Expect & High Level Design
02:50 FSM Design in Animator
06:22 Unity HFSM Key Classes - StateBase.cs, State.cs, StateMachine.cs
07:26 EnemyStateBase.cs Introduction
07:48 EnemyState.cs - Defines all possible states
08:00 StateEvent.cs - Defines all possible events
08:10 Enemy.cs - Set up State Machine with all states
09:58 EnemyStateBase.cs - Base State for all Enemy State Behaviors
11:45 IdleState.cs
12:18 ChaseState.cs
13:31 SpitState.cs & Spit.cs
14:45 AttackState.cs
15:22 BounceState.cs
15:34 RollState.cs
16:15 Add References & Update State Constructors - Enemy.cs
17:49 Detect Player Within Different Ranges - PlayerSensor.cs
18:18 Use Player Sensors - Enemy.cs
19:10 Add Chase/Idle Transitions - Enemy.cs
20:35 Add Roll Transitions - Enemy.cs
21:54 Detect Collisions while Rolling - RollImpactSensor.cs
23:16 Add Transitions to Other Attacks - Enemy.cs
23:58 Set up Objects in Unity Editor & Demo
25:12 Final Thoughts & Support LlamAcademy










