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!
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.
I had found the UnitHFSM a while back before I saw this video but I hadn't really taking the time to learn it. Your code samples helped me get up to speed with it a lot quicker. What I found helped a ton was starting the SM with each individual state as I was working on them so that transition logic wasn't getting in the way. What I've found to be the most challenging thing though is deciding exactly _how_ enemies should behave. Anyone watching this video and working on their own enemy AI should probably try and really figure out first how they want their enemies to behave before diving into implementation. For example, should they begin chasing immediately? How long should they search before giving up? Etc. I originally implemented a basic search that just does random nav mesh sampling near the last known position, but since have built a waypoint system in which enemies can query against based on the last known position so that they don't just stupidly wonder in the same spot...they'll visit each waypoint near where they last saw the player. What I want to do now though if figure out a more automatic solution vs just manually laying down way points, something like a grid placed on the navmesh so that look ups can use simple cell indexes based on the last known position x, z.
That's a great point! This is focused on the "how to implement", not "how to design". The "how to design" is a tricker problem to tackle since it varies on a game-by-game basis. But step #1 in building any AI should be defining the "how do I want this AI to behave"!
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 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...
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
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.
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?
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!
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
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?
I think wayyyy back in part 5 I covered the different enemy types. th-cam.com/video/PoglGJoDcZg/w-d-xo.html 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.
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?
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.
@@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.
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
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. th-cam.com/video/jOp52NQMcTo/w-d-xo.htmlsi=8KuG3QSljWb83YU5 This video I go over a bunch of IK solutions in case you haven’t seen it
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.
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.
@@LlamAcademy I find myself struggling with the same question. For example, if we have a "Move" method that is the same in all states, it would make sense to implement it under Enemy (to avoid duplicating code in states). Otherwise any changes to "Move" would have to be propagated through all states, which is awful. But if we have a special attack that only happens in one specific state, it would make more sense to implement it inside the state? It's kind of difficult to choose sometimes.
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 th-cam.com/video/qt_LkMyNKF4/w-d-xo.html
@@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
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😅
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!
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.
Wow, thanks! That means a lot to me!
This video came out 11 hours ago, my thumbs up came 11 hours too late, wish I could preorder a thumbs up.
Get on it TH-cam! We have an important feature request here!
I had found the UnitHFSM a while back before I saw this video but I hadn't really taking the time to learn it. Your code samples helped me get up to speed with it a lot quicker. What I found helped a ton was starting the SM with each individual state as I was working on them so that transition logic wasn't getting in the way. What I've found to be the most challenging thing though is deciding exactly _how_ enemies should behave. Anyone watching this video and working on their own enemy AI should probably try and really figure out first how they want their enemies to behave before diving into implementation. For example, should they begin chasing immediately? How long should they search before giving up? Etc. I originally implemented a basic search that just does random nav mesh sampling near the last known position, but since have built a waypoint system in which enemies can query against based on the last known position so that they don't just stupidly wonder in the same spot...they'll visit each waypoint near where they last saw the player. What I want to do now though if figure out a more automatic solution vs just manually laying down way points, something like a grid placed on the navmesh so that look ups can use simple cell indexes based on the last known position x, z.
That's a great point! This is focused on the "how to implement", not "how to design". The "how to design" is a tricker problem to tackle since it varies on a game-by-game basis. But step #1 in building any AI should be defining the "how do I want this AI to behave"!
great tutorial cant wait to see how GOP differes, and the lama and its animations are so cute
Have fun 🙂 they’re out already!
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
You can! Just takes some time to get there and understand how it all works 🙂
@@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...
Thank you for sharing such interesting tutorial as well as for effort that went into creating this 🤝
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
Thank You for sharing these Resources.
Definitely useful 💯🎮👍🏻
For the dying state, how about making the llama run away after taking a certain amount of damage.
Hi, i would love that you make a tutorial serie on shooting with dots (players, ennemy's and bullets as entity) the basic
This is great!
thnks for this amazing tuts series
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
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.
@@LlamAcademy Man, so cool that you are answering ! Thanks for the answer! Can't wait for the discord, it could give you visibility !
Great tutorial! What extension are you using in the editor? (The grey notes) That appears to be pretty useful!
I'm using basically the defaults in JetBrains Rider.
@@LlamAcademy oh, I thought it was VS with some extensions. Thanks for the reply ^^
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?
thank you bro can you remake a tuto about floating joystick with animation and also using buttons to jump & fire .
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!
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
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?
I think wayyyy back in part 5 I covered the different enemy types.
th-cam.com/video/PoglGJoDcZg/w-d-xo.html
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.
Thanks a lot!@@LlamAcademy
amazing
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?
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.
@@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.
Fk man this code is hard
Can anyone help me compare this package and State Machine Behavior of Unity, what is the pros and cons of them both
aint no way blud just did ai implementation in one video
💪
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
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. th-cam.com/video/jOp52NQMcTo/w-d-xo.htmlsi=8KuG3QSljWb83YU5
This video I go over a bunch of IK solutions in case you haven’t seen it
Can i use your fsm Ai system implementation in my future project
Of course. You’ll probably want to make some changes for your specific AI though!
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.
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.
@@LlamAcademy I find myself struggling with the same question. For example, if we have a "Move" method that is the same in all states, it would make sense to implement it under Enemy (to avoid duplicating code in states). Otherwise any changes to "Move" would have to be propagated through all states, which is awful.
But if we have a special attack that only happens in one specific state, it would make more sense to implement it inside the state?
It's kind of difficult to choose sometimes.
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 th-cam.com/video/qt_LkMyNKF4/w-d-xo.html
That’s interesting! I didn’t know UVS supported state machines. I will have to take a look at it
@@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
Good experience
nice tutorial where can i find lama and animations?
Linked in the description under “Resources” section!
👏👏👏
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😅
😅 time to implement a framework like state machine or behavior tree!
The Animator is Hell Na!
This is so hard for me to understand 😔
Patreon
second
amazing