Enemy State Machine AI FULL IMPLEMENTATION | AI Series 47 | Unity Tutorial

  Рет қаралды 17,445

LlamAcademy

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.
👨‍💻 As always, all code from this video is available on GitHub: github.com/llamacademy/ai-ser...
👨‍💻 If you're just looking for Unity HFSM, it's here: github.com/Inspiaaa/UnityHFSM
🏷️Save 25% on the ultimate C# IDE: JetBrains Rider with code LLAMACADEMY: www.jetbrains.com/store/?sect...
📚 Resources:
⚫ Unity HFSM: github.com/Inspiaaa/UnityHFSM
⚫ This super cool Llama: assetstore.unity.com/packages...
⚫ Unity Particle Pack (free): assetstore.unity.com/packages...
⚫ AI Series 44 (Movement Prediction): • Better Enemy Chasing w...
⚫ Damage System: • Damage Enemies and Obj...
⚫ Unity 2021 Object Pooling API: • Unity 2021 Object Pool...
⚫ Comparison of AI Behavior Frameworks: • Which AI Behavior Fram...
💸 Ongoing sales 💸
⚫ Check out the latest Humble Bundles www.humblebundle.com/software...
⚫ Publisher Sale! 50% OFF an entire publisher's Assets! Publisher changes weekly! assetstore.unity.com/publishe...
⚫ Save up to 50% on NEW Assets: assetstore.unity.com/?new_sal...
❤ Believe in LlamAcademy's mission and have received value from the videos? Become a Supporter:
⚫ Patreon: / llamacademy
⚫ KZbin Member: / @llamacademy or click the Join button on any video
⚫ GitHub Sponsor: github.com/sponsors/llamacademy
----
I also have some Unity Assets: assetstore.unity.com/publishe...
Some links may be affiliate links, which at no additional cost to you, gives me a small portion of the purchase.
#unitytutorial #tutorialtuesday #gamedev #tutorial #unity #llamacademy #gamedevelopment
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

Пікірлер: 59
@LlamAcademy
@LlamAcademy 9 ай бұрын
Hey all! I hope seeing the end to end implementation of a Finite State Machine using HFSM helps you better understand "how to draw the owl" if you're just getting into AI Behavior design/implementation. And as always...Full code is available on GitHub 👨‍💻: github.com/llamacademy/ai-series-part-47 If you're just looking for Unity HFSM, it's here 👨‍💻 : github.com/Inspiaaa/UnityHFSM Cheers and have fun with your AI!
@dibaterman
@dibaterman 9 ай бұрын
This video came out 11 hours ago, my thumbs up came 11 hours too late, wish I could preorder a thumbs up.
@LlamAcademy
@LlamAcademy 9 ай бұрын
Get on it KZbin! We have an important feature request here!
@sharat.achary
@sharat.achary 9 ай бұрын
Thank you for sharing such interesting tutorial as well as for effort that went into creating this 🤝
@alec_almartson
@alec_almartson 9 ай бұрын
Thank You for sharing these Resources. Definitely useful 💯🎮👍🏻
@amirosman8797
@amirosman8797 9 ай бұрын
Your AI series is an absolute masterpiece! It's remarkable how your tutorials rival, if not surpass, the quality of paid courses. The clarity and depth with which you explain Unity game AI concepts are unparalleled. Thank you for sharing your knowledge with the community.
@LlamAcademy
@LlamAcademy 9 ай бұрын
Wow, thanks! That means a lot to me!
@3network983
@3network983 9 ай бұрын
thnks for this amazing tuts series
@nikefootbag
@nikefootbag 9 ай бұрын
This is great!
@zubairGamX
@zubairGamX 9 ай бұрын
Sir This is Just Amazing Thank you Sooo Much I also Started your AI Series which helps me alot to learn advance thing Thank you SOooo Much
@Pikachu-oo5ro
@Pikachu-oo5ro 9 ай бұрын
For the dying state, how about making the llama run away after taking a certain amount of damage.
@okandikkulak8057
@okandikkulak8057 9 ай бұрын
amazing
@r1s1112
@r1s1112 3 ай бұрын
Great tutorial! What extension are you using in the editor? (The grey notes) That appears to be pretty useful!
@LlamAcademy
@LlamAcademy 3 ай бұрын
I'm using basically the defaults in JetBrains Rider.
@r1s1112
@r1s1112 3 ай бұрын
@@LlamAcademy oh, I thought it was VS with some extensions. Thanks for the reply ^^
@omelette2718
@omelette2718 8 ай бұрын
Loving your content. Binge watching like crazy lately. Can we have your Intellisense settings ? How do you get the little info on each line saying for example "new" or "EventFunction" at 18:15 ? Would you consider creating a discord where fans of yours can interact ? Keep up the good Llama work, OP7
@LlamAcademy
@LlamAcademy 8 ай бұрын
That's awesome to hear! I've finally moved over to using JetBrains Rider. These are the default settings there. Using Visual Studio (not sure about VSCode) you can get similar "Create this function" suggestions when adding delegates. Usually it came up after I typed the "+= " (including space). As for Discord, I did get that suggestion a few times. I honestly just need to spend the time on setting it up and figuring out the structure there.
@omelette2718
@omelette2718 8 ай бұрын
@@LlamAcademy Man, so cool that you are answering ! Thanks for the answer! Can't wait for the discord, it could give you visibility !
@oleksiidrobnyi7439
@oleksiidrobnyi7439 9 ай бұрын
Great video, thank you! Could you please tell me what will be the best way to implement several types of enemies with different behaviors and different states?
@LlamAcademy
@LlamAcademy 9 ай бұрын
I think wayyyy back in part 5 I covered the different enemy types. kzbin.info/www/bejne/hqDKnXqApKmWkMk Following this same pattern, you could have the FSM defined per enemy type and assign it like how we set up the agent config. I think you could create a ScriptableObject per FSM to make it easier to assign.
@oleksiidrobnyi7439
@oleksiidrobnyi7439 9 ай бұрын
Thanks a lot!@@LlamAcademy
@Diablokiller999
@Diablokiller999 8 ай бұрын
OMG I'm trying to implement something like this for myself for half a year now! 6 month of time wasted, this is so awesome, I could've never written that :D
@LlamAcademy
@LlamAcademy 8 ай бұрын
You can! Just takes some time to get there and understand how it all works 🙂
@Diablokiller999
@Diablokiller999 8 ай бұрын
@@LlamAcademy Coming from Computer Science and System Engineering I know FSM in and out, but they are a bit different for Games and that's where I struggle. Synchronising movement states with camera states, combined with Game states and you start throwing messages all over your code. Kinda hard to keep organised...
@amirosman8797
@amirosman8797 9 ай бұрын
If possible, could you consider creating a video or perhaps replying with some insights on building open-world games? I'm particularly interested in learning about the best tools and techniques for optimizing these games to run smoothly on a variety of devices, including mobile. Your knowledge would be greatly appreciated in this area as well. Thanks again for all the fantastic content!
@LlamAcademy
@LlamAcademy 9 ай бұрын
I've had few requests for open world building. I haven't worked on any open world games so any advice I can provide there would be only theoretical. Maybe once I get some time to work on some prototypes including an open world I can make such a video
@Hazzel31337
@Hazzel31337 4 ай бұрын
great tutorial cant wait to see how GOP differes, and the lama and its animations are so cute
@LlamAcademy
@LlamAcademy 4 ай бұрын
Have fun 🙂 they’re out already!
@MO1-EDITS
@MO1-EDITS 9 ай бұрын
thank you bro can you remake a tuto about floating joystick with animation and also using buttons to jump & fire .
@user-yx5bf7dp4s
@user-yx5bf7dp4s 5 ай бұрын
Great tutorial! I would like to ask what if I have different types of enemy? I just do the whole process again and just name it differently like Enemy2IdleState?
@LlamAcademy
@LlamAcademy 5 ай бұрын
Only if you have actually different things for them to do while idle. Then maybe you have something like “MeleeZombieIdle” and “RangedZombieIdle” for example. If they’re just playing different animations then there’s no need to make another state.
@user-yx5bf7dp4s
@user-yx5bf7dp4s 5 ай бұрын
@@LlamAcademy Got it, thank you! I also have a situation that my AI's target is a large object but it's transform as destination is at middle which cause the AI will pass through the target's model trying to get to the destination in middle even it is in attack range because it keep IsNotWithinIdleRange. For now I just added checking IsInMeleeRange inside transition between Attack -> Chase, Attack -> Idle and Idle -> Chase. It work for now, but not sure it is the best way.
@mohokhachai
@mohokhachai 4 ай бұрын
Good experience
@TREXYT
@TREXYT 9 ай бұрын
Hi, i would love that you make a tutorial serie on shooting with dots (players, ennemy's and bullets as entity) the basic
@TheKr0ckeR
@TheKr0ckeR 7 ай бұрын
Great implementation. I have been using FSM's for 2 years. But lately I feel like i am breaking principles by using State Machine, For example, since we know Enemy script already, but we are still passing transform from enemy class itself, so sometimes i find myself where to do the logic and stuff. So since I know enemy already, I create a method in Enemy and simply call this method in the state, so instead of creating logic in state itself, i create it in enemy and just call it. I think we are breaking OPEN Closed principle in state machine right? Since we add to new state, we have a lot of requirements to do , create enum, create state class itself, and define it in FSM etc. What do you think about that? I generally hold all the stuffs inside Enemy and i call it in states, so instead of passing target to state, I use that target in a method in enemy class and call it from there.
@LlamAcademy
@LlamAcademy 7 ай бұрын
I prefer to have the code related to the state within the State class itself. The State Machine just handles the transitions & events, each State can control the behavior of the AI in that state. If we start putting a bunch of code into "Enemy" it becomes a huge class and it can be difficult to maintain. As with most things...If you have relatively simple behaviors, it probably doesn't make much of a difference. As you need to add more and more complexity to the behaviors you start bumping into the limitations and see the problems that highlight why things like the "Open & Closed" principle were created in the first place. Sometimes we can over-engineer things though, so I don't like to give "NEVER DO X". Generally, I prefer this style of implementation. In some cases though, this will be overkill and harder to see what is going on. Even in the comments over here there are some saying it is too complex or hard to follow.
@im_an_intern_unity_dev
@im_an_intern_unity_dev 8 ай бұрын
Can anyone help me compare this package and State Machine Behavior of Unity, what is the pros and cons of them both
@RecepKartal
@RecepKartal 9 ай бұрын
Bir tane uygulamadaki hata bir türlü çözemedim onlarca kaynaktan araştırmama rağmen hiçbir çözüm bulamadım bu konuda yardımcı olur musunuz acaba -- I could not solve a single error in the application, although I searched from dozens of sources, I could not find any solution, can you help me on this issue?
@__Rizzler__
@__Rizzler__ 9 ай бұрын
aint no way blud just did ai implementation in one video
@LlamAcademy
@LlamAcademy 9 ай бұрын
💪
@JackMartison
@JackMartison 9 ай бұрын
Hey, I may be a little late, but can I request tutorial for ik interaction with the door, not that one time interactions when openingq the door, but when holding the hand on the door and pushing it to open
@LlamAcademy
@LlamAcademy 9 ай бұрын
That’s a cool idea. I will add it to my list. Though I think Interactor provides a great way to do this out of the box. kzbin.info/www/bejne/oIDTZmWEhrKWitEsi=8KuG3QSljWb83YU5 This video I go over a bunch of IK solutions in case you haven’t seen it
@ggwp8618
@ggwp8618 9 ай бұрын
Fk man this code is hard
@vlad_oS1
@vlad_oS1 9 ай бұрын
👏👏👏
@mohokhachai
@mohokhachai 9 ай бұрын
Can i use your fsm Ai system implementation in my future project
@LlamAcademy
@LlamAcademy 9 ай бұрын
Of course. You’ll probably want to make some changes for your specific AI though!
@bonse2000
@bonse2000 9 ай бұрын
nice tutorial where can i find lama and animations?
@LlamAcademy
@LlamAcademy 9 ай бұрын
Linked in the description under “Resources” section!
@k-6353
@k-6353 5 ай бұрын
My Ai is already at 1000 lines of code in a single script lmaoo. It only has roam, idle, attack, go back to last (player pos, and spawn point). Takes me atleast a day to fix a simple behavior bug from tantamount of if conditions😅
@LlamAcademy
@LlamAcademy 5 ай бұрын
😅 time to implement a framework like state machine or behavior tree!
@vaibhavjaiswal799
@vaibhavjaiswal799 9 ай бұрын
Unity Visual Scripting provide visual solution for complex state machines And you can use both your code (methods and properties) and visual scripting to perform operations (Tip: if anyone use it, create a custom editor menu option for units update, bolt has it but UVS not) not promoting but just for reference I have made this previous using UVS kzbin.info/www/bejne/p6XCfZ6DrrN-fJY
@LlamAcademy
@LlamAcademy 9 ай бұрын
That’s interesting! I didn’t know UVS supported state machines. I will have to take a look at it
@vaibhavjaiswal799
@vaibhavjaiswal799 9 ай бұрын
@@LlamAcademy yes it does and best part is you can call your methods of C# code via visual state nodes While using keep my tip in mind it will save lots of time It basically update the code side part in UVS so that it could be accessed in it as nodes
@waleedsaeed8
@waleedsaeed8 4 ай бұрын
The Animator is Hell Na!
@mohokhachai
@mohokhachai 4 ай бұрын
Patreon
@wizzely7718
@wizzely7718 8 ай бұрын
This is so hard for me to understand 😔
@giannisspernovasilis4266
@giannisspernovasilis4266 9 ай бұрын
second
@Forture-fm1ve
@Forture-fm1ve 9 ай бұрын
amazing
Which AI Behavior Framework Should You Use? | AI Series 46
17:26
LlamAcademy
Рет қаралды 35 М.
🍟Best French Fries Homemade #cooking #shorts
00:42
BANKII
Рет қаралды 32 МЛН
How many pencils can hold me up?
00:40
A4
Рет қаралды 18 МЛН
Тяжелые будни жены
00:46
К-Media
Рет қаралды 5 МЛН
Miracle Doctor Saves Blind Girl ❤️
00:59
Alan Chikin Chow
Рет қаралды 49 МЛН
Creating SMART enemies from scratch! | Devlog
5:40
Challacade
Рет қаралды 256 М.
Giving Personality to Procedural Animations using Math
15:30
t3ssel8r
Рет қаралды 2,4 МЛН
GOAP Enemy AI FULL IMPLEMENTATION | AI Series 50 | Unity Tutorial
1:10:13
2D PATHFINDING - Enemy AI in Unity
23:13
Brackeys
Рет қаралды 799 М.
Escaping Unity Animator HELL
18:18
Lost Relic Games
Рет қаралды 492 М.
How to Program in Unity: State Machines Explained
18:56
iHeartGameDev
Рет қаралды 211 М.
ADVANCED AI IN UNITY (Made EASY) - STATE MACHINE BEHAVIORS
8:15
Blackthornprod
Рет қаралды 234 М.
Unity Bots with State Machines - Extensible State Machine / FSM
37:45
Jason Weimann
Рет қаралды 117 М.
🍟Best French Fries Homemade #cooking #shorts
00:42
BANKII
Рет қаралды 32 МЛН