GOAP Enemy AI FULL IMPLEMENTATION | AI Series 50 | Unity Tutorial

Поділитися
Вставка
  • Опубліковано 2 жов 2024

КОМЕНТАРІ • 98

  • @LlamAcademy
    @LlamAcademy  9 місяців тому +6

    Go to this video's Sponsor: snhu.edu/llamacademy to see what the current average annual salary for a game developer programmer is and learn how you can get started!
    Special thanks to @CrashKonijn for all his work on the GOAP system used in this video!
    ⚫ FREE Unity GOAP System used here: github.com/crashkonijn/GOAP
    ⚫ GOAP System Documentation: goap.crashkonijn.com/
    ⚫ Introduction to GOAP: ua-cam.com/video/3PLDIEjmQsI/v-deo.html
    ⚫ Factory Pattern: en.wikipedia.org/wiki/Factory_(object-oriented_programming)
    ⚫ Builder Pattern: en.wikipedia.org/wiki/Builder_pattern
    ⚫ AI Series 4 Runtime Agent Spawning: ua-cam.com/video/5uO0dXYbL-s/v-deo.html
    ⚫ Dependency Injection: en.wikipedia.org/wiki/Dependency_injection
    ⚫ Which AI Behavior Framework Should You Use? ua-cam.com/video/CZvfuNfdc1M/v-deo.html

  • @CrashKonijn
    @CrashKonijn 9 місяців тому +18

    Amazing job Chris! Thank you for creating this tutorial! ❤

    • @LlamAcademy
      @LlamAcademy  9 місяців тому +6

      Thanks for all your work on the system 🧡!

    • @Michael-es6qw
      @Michael-es6qw 9 місяців тому

      I downloaded your GOAP system some time ago, and now there is also a UA-cam tutorial for it! Amazing, this just made my day 🥹

    • @greenfoxgrasstail2534
      @greenfoxgrasstail2534 9 місяців тому +2

      Thanks for makeing that GOAP System.
      My last time i tried makeing a game i wanted. It failed cause my AI just didnt feel right.
      I'm barely starting to use this approach and its already so much more what i wanted.
      Gonna look up that sponsor thingy, that's new.

  • @evanciao
    @evanciao 9 місяців тому +1

    Finally! Thank you so much for creating this tutorial!

    • @LlamAcademy
      @LlamAcademy  9 місяців тому +1

      It took me over a month to put it together but I think it will be really helpful for a lot of people!

  • @kronusbr17
    @kronusbr17 9 місяців тому +1

    Amazing channel!!! The best unity tutorials in the internet ❤❤❤

  • @qwetzq9757
    @qwetzq9757 7 місяців тому +4

    Like if you like his cringe signature move at the beginning of each video 😂❤

    • @LlamAcademy
      @LlamAcademy  7 місяців тому +1

      👍 at least one from me!

  • @alec_almartson
    @alec_almartson 9 місяців тому +2

    Great content 🔥🎮💯👏🏻🤟🏻
    I can't wait to try this AI Setup on my Game Demo. Thank You

  • @O2Dev
    @O2Dev 9 місяців тому +1

    Amazing job! Just finished it. What a great tutorial and library!
    I noticed when the Llama wants to eat, if no grass is in range, it gets stuck in place doing the EatAction anyway.
    To fix this, should I add a condition like PlayerDistance (GrassDistance) to the EatAction, so it keeps Wandering if no food is around? Or is there another way?
    Anyway, thanks a lot!

    • @LlamAcademy
      @LlamAcademy  9 місяців тому +1

      That's a great question. I made the assumption there would always be some kind of grass in range since we didn't make it a depletable resource. In the event that there is no grass and you cannot perform the action, you can assign a NoActionFound delegate to handle this case on the "AgentBehaviour.Events" in the LlamaBrain

  • @rbr0319
    @rbr0319 4 місяці тому

    Hello there, i just found out about your channel and im loving the ai series, i would like to know if you think about making a video on HTN (hierarchical task network), wich as far as i understood is a upgrade to goap.

    • @LlamAcademy
      @LlamAcademy  4 місяці тому +1

      I have not considered that yet. I'll give it some thought

  • @usercontent2112
    @usercontent2112 9 місяців тому

    Epic intro!

    • @usercontent2112
      @usercontent2112 9 місяців тому

      Thank you for explaining in details about GOAP!

    • @LlamAcademy
      @LlamAcademy  9 місяців тому

      💪 thanks 😊

  • @Damian_h
    @Damian_h 9 місяців тому +1

    Llam bro i have a question. I have a character that has animations for all directions forward, backward, strafe left and right but i also wanna implement jogs stop animations for every direction to make the movement feels a bit more smooth. The thing is i set up the blend tree 2d and the movement is looking good the problem is i dont know where should or how should I add the jogs stop animations i dont know if it should be individuals transitions from the motion blend to those stop animation or i should make another blend tree whats the best way to implement stop animations and which conditions should trigger these kind of animations that are pretty much executing almost when there is no speed value left.

    • @5ld734
      @5ld734 6 місяців тому

      I think you can create another blend tree and use the same direction condition as the regular movement,
      It might help to just call an animator trigger to transition to the stop blend tree when the character is stopped

  • @sneddengonsalves9320
    @sneddengonsalves9320 4 дні тому

    @ 21:54 what is the purpose of the --GOAP Config game object?

    • @LlamAcademy
      @LlamAcademy  2 дні тому +1

      I made this GameObject just to house those key GOAP Initializers. These MonoBehaviours must be in the scene for the GOAP system to work. We hook it up to the agents via the Goap Set Binder on the individual agents shortly after that timestamp

  • @Colo629
    @Colo629 5 місяців тому +1

    Very helpful. Never thought I'd be implementing GOAP AI any time soon, but this crash course has got me on my way. Thank you.

    • @LlamAcademy
      @LlamAcademy  5 місяців тому

      Have fun! Once you have all the concepts down it ends up being pretty straightforward, but there's a lot to get into your head before that moment happens 😋

  • @ZangJM
    @ZangJM 4 місяці тому

    Hello I'm new to the series, In which video the CommonData.cs script is?

    • @LlamAcademy
      @LlamAcademy  4 місяці тому +1

      In this video around 08:09

  • @ducnguyenzz
    @ducnguyenzz 9 місяців тому

    amazing

  • @bluzenkk
    @bluzenkk 9 місяців тому +2

    Question, is GOAP a cpu intensive system that will impact performance?
    If i want to make a game like Let's School, and there could be more than 200-500 ai at the same time, is GOAP a good choice?

    • @CrashKonijn
      @CrashKonijn 9 місяців тому +2

      Hi there!
      Yes, resolving a graph using A* is considered expensive. However it all depends on how large the graph is that needs to be resolved. As for running 500 agents; resolving a new action for 500 agents in a single frame is probably too much. Luckily that's probably not needed, since they won't have to resolve anything wile running their actions.

    • @LlamAcademy
      @LlamAcademy  9 місяців тому +1

      As CrashKonijn mentioned here, having 200-500 AI evaluating their goals every frame would not perform very well. Most likely you will not have all 200-500 picking goals and sensing every frame though because they would be performing some actions that would take time.
      This system makes use of the jobs system to make it highly efficient.
      In any game with large quantities of AI you have to evaluate performance and see what can be done to meet your requirements on your target hardware. In many games AI that are "far away" are just disabled, or have a reduced update frequency to make it more performant.

    • @youl-x3g
      @youl-x3g 7 місяців тому

      Does the framework support agent's goal-based decision-making across frames?@@CrashKonijn

    • @CrashKonijn
      @CrashKonijn 7 місяців тому

      ​@@youl-x3g Hi there!
      You mean the planner taking multiple frames to calculate what the best action would be? No it doesn't support that currently.

    • @youl-x3g
      @youl-x3g 7 місяців тому

      Okay, I understand, thanks

  • @andrewz8763
    @andrewz8763 Місяць тому

    Just discovered your channel and your AI series is top notch! 👍Do you plan on revisiting the GOAP system by CrashKonijn once V3 is out of Beta?

    • @LlamAcademy
      @LlamAcademy  Місяць тому +1

      🙂 I think so

    • @andrewz8763
      @andrewz8763 Місяць тому

      @@LlamAcademy That would be great! I think there would be value in covering the TransformTarget type that is part of v2.1 as well. It's used in the complex example, and once I discovered it it made a huge difference on what I needed to do in order to handle orientations of characters when they reached a position.

  • @hunterfox6230
    @hunterfox6230 5 місяців тому

    What exactly is the difference between PlayerTargetSensor and PlayerSensor? Each one is in a different folder? Should I be naming them differently so as not to confuse a GOAP sensor with something else?

    • @LlamAcademy
      @LlamAcademy  5 місяців тому

      PlayerSensor senses the player (monobehavior) so the brain can tell the GOAP System to change the goal. You can change the name if it is confusing between this and the GOAP Sensor.

  • @jutekpixel
    @jutekpixel 4 місяці тому

    It is great tu great tutorial, there is one thing i don't understand. In "AttackData" script, how did you make link to Animator? How can I reference other objects there? I am changing animations from other script like "agentController" but I cannot get references to this one.

    • @LlamAcademy
      @LlamAcademy  4 місяці тому +1

      I did it with the [GetComponent] annotation from the GOAP system we’re using here. You can assign it manually with a standard GetComponent as well.

    • @jutekpixel
      @jutekpixel 4 місяці тому

      @@LlamAcademy Hi and thank you for the hint. I was actually playing with this system for a past few days and it is really cool. I am doing some small modifications to make it compatible with A* Project, and it looks very promising so far. :)
      One observation that I want to make, for actions and sensors it is not really necessary to have an Injection system. It is perfectly fine to grab a lot of info with [GetComponent] annotation.

    • @jutekpixel
      @jutekpixel 3 місяці тому +1

      @@LlamAcademy Hi again, I have to say this tool is amazing. Ever since I have seen your tutorial (two weeks ago) I have started to play with it. Maybe because I am not from IT world, so it took me some time to understand, but I am starting to get it now and having some nice results. :) Thanks for this tutorial. Cheers!

  • @maximdaigle
    @maximdaigle 4 місяці тому

    Would I need another GoapSetConfigFactory with its specific dependency injector if I wanted to support multiple types of enemies/NPCs ?
    I'd guess I could rewrite the GoapSetBinder to take in a SetName.
    What if I want the same enemy type to have different Configs?
    Also using the ScriptableObjects configs could lead to errors no? In the sense that you could put two different configs one on the GOAP system and another wrong one on the behaviours.
    What if the same action is used by different enemies?
    Maybe these values could come from the CommonData? thoughts?

    • @LlamAcademy
      @LlamAcademy  4 місяці тому +1

      Regarding the DependencyInjector, it depends on how divergent your enemy types are. If you have them set up with pluggable behaviors and configurations like what we've set up here, you can likely use the same DependencyInjector.
      If your AI will have totally different goals, then you will probably need different GoapSets. That could be handled all in one GoapSetConfigFactory, or you could have multiple.
      Regarding the ScriptableObjects, because they're just data you can create as many as you'd like. I think we have it designed a little simplistically here because we only have the 1 enemy type. You'd probably need some kind of data model linking the configurations to the enemy type so we don't run into the problem you're describing.

    • @maximdaigle
      @maximdaigle 4 місяці тому

      ​@@LlamAcademy thank you so much for the answer! I managed a solution for multiple agent types :)

  • @youl-x3g
    @youl-x3g 7 місяців тому +1

    Thank you very much for your tutorial, but I have a few questions. If a character can learn skills, how do I dynamically modify the GOAP (Goal Oriented Action Planning) set, and each skill has its own range? Do I need to write multiple sensors, or is one sensor for enemy range sufficient? Also, it seems that the GOAP system includes a planner component. So far, in the tutorial, I've seen the use of FSM (Finite State Machine) and hard-coded methods. Does this GOAP framework provide a planner similar to priority planning?

    • @youl-x3g
      @youl-x3g 7 місяців тому

      Perhaps you might also need to dynamically construct the goal set to reduce the number of A* computations.

    • @LlamAcademy
      @LlamAcademy  7 місяців тому

      You can configure the GOAP set up front with all the possible skills and as part of the sensors detect if they’re unlocked or not at that moment. CrashKonjin is also considering implementing an ability to dynamically enable/disable actions. As far as I know that’s not implemented yet, but would be a little more convenient than the sensor method.
      As for the planner. The GOAP system does have a default planner that plans based on the cost and the actions (including distance traveling) available to achieve the current goal. You can even create your own custom planner if you’re super hardcore 🙂

    • @youl-x3g
      @youl-x3g 7 місяців тому

      Thank you. After considering it, I believe that using GOAP for skill casting decisions may not be suitable. This is because skill casting does not require too many actively fulfilled prerequisites; it only needs some passive conditions to be met for casting. @@LlamAcademy

  • @hunterfox6230
    @hunterfox6230 5 місяців тому

    @ 33:12 my "Player" type in "if (other.TryGetComponent(out Player player))" is throwing an error. I see Player.cs in your folder structure, but you don't go over whats in it?

    • @hunterfox6230
      @hunterfox6230 5 місяців тому

      Additionally, how are we tracking player health? The PlayerHealth script doesn't have a float to track health?

    • @LlamAcademy
      @LlamAcademy  5 місяців тому +1

      Good point. This is an almost- empty monobehavior I use to identify that this object is a player.
      You can find the full project code on GitHub if you ever want to see anything I may have skipped in the video: github.com/llamacademy/ai-series-part-50

    • @hunterfox6230
      @hunterfox6230 5 місяців тому

      @@LlamAcademy Thank you so much for sharing this! I can look into that script now. I see that we set up the Factory to look at PlayerHealth, but PlayerHealth is actually an empty scripp with no float? How do we actually read player health and affect it?

  • @Hazzel31337
    @Hazzel31337 8 місяців тому

    thanks verry complex, reminds me of the DOTS tutorial

  • @3network983
    @3network983 9 місяців тому

    thanks

  • @PRodi_
    @PRodi_ 9 місяців тому

    Is GOAP a good way to make 3D games similar to Vampire Survivors?

    • @LlamAcademy
      @LlamAcademy  9 місяців тому +1

      I do not think you need a system as sophisticated GOAP for the AI in a game like Vampire Survivors.

  • @yours_indie_game_dev
    @yours_indie_game_dev 9 місяців тому

    does it only work with navmesh agent. what if my ai moves with rgidbody instead

    • @LlamAcademy
      @LlamAcademy  9 місяців тому

      Yes of course you can use a Rigidbody as well 🙂

  • @janowazir
    @janowazir 9 місяців тому

    I am again here can you make a video about how to give multiple tags to one gameobject🤚Please SIR

    • @Onyhh
      @Onyhh 9 місяців тому +1

      why would u want to do that?

  • @hunterfox6230
    @hunterfox6230 5 місяців тому

    Hey! Great video! So a@30:25 with the line
    bool shouldAttack = data.Target != null && Vector3.Distance(a: data.Target.Position, b: agent.transform.position)

    • @LlamAcademy
      @LlamAcademy  5 місяців тому +1

      I think maybe you named your AttackConfigSO variable differently than me. This should be the variable that is of type AttackConfigSO

    • @hunterfox6230
      @hunterfox6230 5 місяців тому

      @@LlamAcademy I figured it out! I somehow missed the part where I needed to Inject into the MeleeAction script. Thank you for the help!

  • @LupoNoBrain
    @LupoNoBrain 5 місяців тому

    Hi @LlamAcademy,
    Thank you for this great entry into the topic. I am facing a rather embarrassing issue:
    I have followed your instructions precisely, but I keep getting this error:
    "KeyNotFoundException: No goapSet with id TestSet found"
    Now even if I manually call the Creation on my GoapSetConfigFactory and make sure the Set is created, it is never finding it for me.
    Any suggestions would be appreciated. Thanks again for your awesome video.

    • @LupoNoBrain
      @LupoNoBrain 5 місяців тому

      Nevermind, I tried to include my own naming conventions already and messed something up along the way. It works now, thanks again! :D

    • @LlamAcademy
      @LlamAcademy  5 місяців тому

      😁 Glad you got it up and running!

  • @PodCast3_6_9
    @PodCast3_6_9 7 місяців тому

    Bravo Proud ......

  • @rbr0319
    @rbr0319 4 місяці тому

    Hey man, i had some doubts about the implementation and would like to know if you have a group on discord that could help me ?

    • @LlamAcademy
      @LlamAcademy  3 місяці тому

      The only Discord I have is exclusive for UA-cam members / Patreon supporters.

  • @Rizzmaster9001
    @Rizzmaster9001 7 місяців тому +1

    at 11:00 you are going WAY too fast. I have no idea where the Events or ITargets came from. You never specified to import GOAP interfaces

    • @kodaxmax
      @kodaxmax 7 місяців тому

      im confused about the itargets to. All it seems to do is pass a vector3 from... somehwere? presumably the target but i dont get how.

    • @LlamAcademy
      @LlamAcademy  7 місяців тому +1

      Hi! The ITarget is populated by the GOAP system based on your Sensor. Around 06:00 you can see where we created the ITarget. This is the same value that is passed over to this AgentMoveBehavior

  • @Trinimp
    @Trinimp 8 місяців тому

    How do you get the unity intelisense to show for goap. Im hoping this is a simple question and im just overthinking it

    • @LlamAcademy
      @LlamAcademy  8 місяців тому +1

      After you import the package it should just show up for you automatically. At least it did for me.

    • @Trinimp
      @Trinimp 8 місяців тому

      @@LlamAcademy okay so maybe i messed up the set up of visual studio and unity integration

    • @Trinimp
      @Trinimp 8 місяців тому

      I completely reinstall and found the issue I believe, might have been multiple, but I had a C# Dev kit active turning that off was the nail in the coffin.
      However I have another question and I greatly appreciate you taking the time to respond
      5:13 how did you do that where it generated all the code you were going to need for the sensor.

    • @LlamAcademy
      @LlamAcademy  8 місяців тому +1

      The codegen is to “Implement Missing Members” on Rider the hotkey for quick actions is alt+enter. I think in visual studio it’s like… control + . Or something like that. You can right click to get the menu too.

    • @Trinimp
      @Trinimp 8 місяців тому +1

      @LlamAcademy thank you so much. It's small things like this that really get to me. You are a legend. I'll make sure to give you a share on my socials

  • @greenfoxgrasstail2534
    @greenfoxgrasstail2534 9 місяців тому

    Throwing errors when i try to load the git from you.
    Managed to get the goap system just fine from crahkojin... Maybe i am to stupid .
    Just wanted to to mess around with it before trying to do it for what i am planning. xD
    Guess i will just go straight into codeing and testing it out myself.

    • @LlamAcademy
      @LlamAcademy  9 місяців тому

      I’m sure it’s not that you are stupid 🙂. Let me check the repo. I probably messed something up!

    • @LlamAcademy
      @LlamAcademy  9 місяців тому

      I pulled it fresh from the GitHub and it was working except the missing llama model (just had to import him from the Asset Store). What errors were you getting?

    • @greenfoxgrasstail2534
      @greenfoxgrasstail2534 9 місяців тому

      ​@@LlamAcademy [Package Manager Window] Error adding package:
      Unable to add package :
      does not point to a valid package. No package manifest was found.

    • @greenfoxgrasstail2534
      @greenfoxgrasstail2534 9 місяців тому

      @@LlamAcademy Doesnt wanna let me copy paste it into comments here xD... "no package manifest found". So i guess it cant see the package when i try loading it over the git hub link

    • @greenfoxgrasstail2534
      @greenfoxgrasstail2534 9 місяців тому

      nvm ....there it is. Showed up ... after i posted something else. UA-cam... doesnt like it if theres links in comments. So i had to get rid of the github link.. xD Couldnt poste the error before...

  • @criminalbotanist
    @criminalbotanist 3 місяці тому

    Man all this AI playlist is incredible. I followed and made projects with many of the examples you show. Truly appreciated!
    If i wanted to make a everyone vs everyone king of the hill type of game, where we had the player and 9 AI agents, all fighting and pushing each other to stay on top of the hill for the longest time, could i simply modify this GOAP system?
    Here's an example of the desired end result: ua-cam.com/video/oDGgwKKGIpg/v-deo.html

    • @LlamAcademy
      @LlamAcademy  3 місяці тому

      You can absolutely use GOAP for the AI Agents on a King of the Hill game. It's all about setting up the goals, potential actions, and knowledge the world! :)

  • @janowazir
    @janowazir 9 місяців тому

    can you make a video about how to give an array inside an array plaease

    • @LlamAcademy
      @LlamAcademy  9 місяців тому

      Array inside array? like a 2 dimensional array? You can simply do int[][] twoDimensionalArray = new int[5][5];
      Here's Microsoft's C# documentation on the subject: learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/arrays

    • @janowazir
      @janowazir 9 місяців тому

      @@LlamAcademy 👋But make a video about it

    • @5ld734
      @5ld734 6 місяців тому

      You can also do array[x,y,z] if you are in C# unity
      basically just add a comma to add another dimension