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

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 พ.ย. 2024

ความคิดเห็น • 62

  • @LlamAcademy
    @LlamAcademy  ปีที่แล้ว +10

    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!

  • @amirosman8797
    @amirosman8797 ปีที่แล้ว +3

    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  ปีที่แล้ว +1

      Wow, thanks! That means a lot to me!

  • @dibaterman
    @dibaterman ปีที่แล้ว +6

    This video came out 11 hours ago, my thumbs up came 11 hours too late, wish I could preorder a thumbs up.

    • @LlamAcademy
      @LlamAcademy  ปีที่แล้ว +1

      Get on it TH-cam! We have an important feature request here!

  • @JasonWelch
    @JasonWelch 3 หลายเดือนก่อน

    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.

    • @LlamAcademy
      @LlamAcademy  3 หลายเดือนก่อน

      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"!

  • @Hazzel31337
    @Hazzel31337 10 หลายเดือนก่อน +1

    great tutorial cant wait to see how GOP differes, and the lama and its animations are so cute

    • @LlamAcademy
      @LlamAcademy  10 หลายเดือนก่อน

      Have fun 🙂 they’re out already!

  • @Diablokiller999
    @Diablokiller999 ปีที่แล้ว +1

    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  ปีที่แล้ว +1

      You can! Just takes some time to get there and understand how it all works 🙂

    • @Diablokiller999
      @Diablokiller999 ปีที่แล้ว

      @@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...

  • @sharat.achary
    @sharat.achary ปีที่แล้ว +2

    Thank you for sharing such interesting tutorial as well as for effort that went into creating this 🤝

  • @zubairGamX
    @zubairGamX ปีที่แล้ว +1

    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

  • @alec_almartson
    @alec_almartson ปีที่แล้ว +1

    Thank You for sharing these Resources.
    Definitely useful 💯🎮👍🏻

  • @Pikachu-oo5ro
    @Pikachu-oo5ro ปีที่แล้ว +3

    For the dying state, how about making the llama run away after taking a certain amount of damage.

  • @TREXYT
    @TREXYT ปีที่แล้ว

    Hi, i would love that you make a tutorial serie on shooting with dots (players, ennemy's and bullets as entity) the basic

  • @nikefootbag
    @nikefootbag ปีที่แล้ว +2

    This is great!

  • @3network983
    @3network983 ปีที่แล้ว +1

    thnks for this amazing tuts series

  • @omelette2718
    @omelette2718 ปีที่แล้ว +1

    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  ปีที่แล้ว +1

      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 ปีที่แล้ว +1

      @@LlamAcademy Man, so cool that you are answering ! Thanks for the answer! Can't wait for the discord, it could give you visibility !

  • @r1s1112
    @r1s1112 9 หลายเดือนก่อน

    Great tutorial! What extension are you using in the editor? (The grey notes) That appears to be pretty useful!

    • @LlamAcademy
      @LlamAcademy  9 หลายเดือนก่อน +1

      I'm using basically the defaults in JetBrains Rider.

    • @r1s1112
      @r1s1112 9 หลายเดือนก่อน

      @@LlamAcademy oh, I thought it was VS with some extensions. Thanks for the reply ^^

  • @RecepKartal
    @RecepKartal ปีที่แล้ว

    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?

  • @MO1-EDITS
    @MO1-EDITS ปีที่แล้ว +1

    thank you bro can you remake a tuto about floating joystick with animation and also using buttons to jump & fire .

  • @amirosman8797
    @amirosman8797 ปีที่แล้ว

    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  ปีที่แล้ว +1

      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

  • @oleksiidrobnyi7439
    @oleksiidrobnyi7439 ปีที่แล้ว

    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  ปีที่แล้ว +1

      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.

    • @oleksiidrobnyi7439
      @oleksiidrobnyi7439 ปีที่แล้ว

      Thanks a lot!@@LlamAcademy

  • @okandikkulak8057
    @okandikkulak8057 ปีที่แล้ว +2

    amazing

  • @友贤
    @友贤 11 หลายเดือนก่อน

    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  11 หลายเดือนก่อน +1

      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.

    • @友贤
      @友贤 10 หลายเดือนก่อน

      @@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.

  • @ggwp8618
    @ggwp8618 ปีที่แล้ว +3

    Fk man this code is hard

  • @im_an_intern_unity_dev
    @im_an_intern_unity_dev ปีที่แล้ว +1

    Can anyone help me compare this package and State Machine Behavior of Unity, what is the pros and cons of them both

  • @__Rizzler__
    @__Rizzler__ ปีที่แล้ว +3

    aint no way blud just did ai implementation in one video

  • @JackMartison
    @JackMartison ปีที่แล้ว

    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  ปีที่แล้ว

      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

  • @mohokhachai
    @mohokhachai ปีที่แล้ว

    Can i use your fsm Ai system implementation in my future project

    • @LlamAcademy
      @LlamAcademy  ปีที่แล้ว

      Of course. You’ll probably want to make some changes for your specific AI though!

  • @TheKr0ckeR
    @TheKr0ckeR ปีที่แล้ว

    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  ปีที่แล้ว +1

      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.

    • @TheyDoDream
      @TheyDoDream 2 หลายเดือนก่อน

      @@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.

  • @vaibhavjaiswal799
    @vaibhavjaiswal799 ปีที่แล้ว +1

    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
      @LlamAcademy  ปีที่แล้ว

      That’s interesting! I didn’t know UVS supported state machines. I will have to take a look at it

    • @vaibhavjaiswal799
      @vaibhavjaiswal799 ปีที่แล้ว

      @@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

  • @mohokhachai
    @mohokhachai 10 หลายเดือนก่อน

    Good experience

  • @bonse2000
    @bonse2000 ปีที่แล้ว

    nice tutorial where can i find lama and animations?

    • @LlamAcademy
      @LlamAcademy  ปีที่แล้ว

      Linked in the description under “Resources” section!

  • @vlad_oS1
    @vlad_oS1 ปีที่แล้ว +2

    👏👏👏

  • @k-6353
    @k-6353 11 หลายเดือนก่อน +1

    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  11 หลายเดือนก่อน

      😅 time to implement a framework like state machine or behavior tree!

  • @LIDOGAMES
    @LIDOGAMES 10 หลายเดือนก่อน

    The Animator is Hell Na!

  • @wizzely7718
    @wizzely7718 ปีที่แล้ว

    This is so hard for me to understand 😔

  • @mohokhachai
    @mohokhachai 10 หลายเดือนก่อน

    Patreon

  • @giannisspernovasilis4266
    @giannisspernovasilis4266 ปีที่แล้ว

    second

  • @Forture-fm1ve
    @Forture-fm1ve ปีที่แล้ว +1

    amazing