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

Поделиться
HTML-код
  • Опубликовано: 2 янв 2025

Комментарии •

  • @LlamAcademy
    @LlamAcademy  Год назад +7

    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: ruclips.net/video/3PLDIEjmQsI/видео.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: ruclips.net/video/5uO0dXYbL-s/видео.html
    ⚫ Dependency Injection: en.wikipedia.org/wiki/Dependency_injection
    ⚫ Which AI Behavior Framework Should You Use? ruclips.net/video/CZvfuNfdc1M/видео.html

  • @dogauslu
    @dogauslu 12 дней назад +2

    Thank you for this! Creators, developers, artists...you name it - folks like you make late-bloomers like me dare and brave the waters of indie game development.

  • @CrashKonijn
    @CrashKonijn Год назад +19

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

    • @LlamAcademy
      @LlamAcademy  Год назад +6

      Thanks for all your work on the system 🧡!

    • @Michael-es6qw
      @Michael-es6qw Год назад

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

    • @greenfoxgrasstail2534
      @greenfoxgrasstail2534 Год назад +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.

  • @Colo629
    @Colo629 8 месяцев назад +2

    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  8 месяцев назад

      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 😋

  • @eatower2
    @eatower2 2 месяца назад

    This was incredible, both by you and CrashKonijn! I know this might be niche, but I'm starting to implement this into a more Manager type game, and was wondering if you would consider a video about multiple agent factions and their interactions in this series. Possibly using this GOAP framework if that is something you would enjoy diving deeper on. You're videos have been incredibly helpful and I will continue referencing this series and your other videos no matter what. Thanks for all your hark work.

  • @evanciao
    @evanciao Год назад +1

    Finally! Thank you so much for creating this tutorial!

    • @LlamAcademy
      @LlamAcademy  Год назад +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 Год назад +1

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

  • @alec_almartson
    @alec_almartson Год назад +2

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

  • @diegoleao
    @diegoleao 2 месяца назад

    I can't unhear it: you sound exactly like Conan O'Brien 😂 Also, great video ❤

  • @O2Dev
    @O2Dev Год назад +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  Год назад +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

  • @sneddengonsalves9320
    @sneddengonsalves9320 3 месяца назад

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

    • @LlamAcademy
      @LlamAcademy  3 месяца назад +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

  • @Damian_DH
    @Damian_DH Год назад +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 10 месяцев назад

      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

  • @bluzenkk
    @bluzenkk Год назад +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 Год назад +3

      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  Год назад +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 10 месяцев назад

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

    • @CrashKonijn
      @CrashKonijn 10 месяцев назад

      ​@@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 10 месяцев назад

      Okay, I understand, thanks

  • @youl-x3g
    @youl-x3g 10 месяцев назад +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 10 месяцев назад

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

    • @LlamAcademy
      @LlamAcademy  10 месяцев назад

      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 10 месяцев назад

      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

  • @sneddengonsalves9320
    @sneddengonsalves9320 2 месяца назад

    hey in the sensers for you code you either returns ITarget impl or SenseValue , I want to get a reference to the transform of the ITarget that was returned, can you do that?

    • @LlamAcademy
      @LlamAcademy  2 месяца назад

      Yes! The ITarget can be a TransformTarget which will give you the Transform reference. On the docs page here you can see he's doing exactly that: goap.crashkonijn.com/classes/sensors

  • @usercontent2112
    @usercontent2112 Год назад

    Epic intro!

  • @rbr0319
    @rbr0319 7 месяцев назад

    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  7 месяцев назад +1

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

  • @Boy132DE
    @Boy132DE 15 дней назад

    Very nice tutorial! But can you please make an updated version for v3 of the GOAP system? Thanks!

    • @LlamAcademy
      @LlamAcademy  7 дней назад

      I do intend to get around to that. This length of video takes a VERY long time to put together so I need to get enough time to really dive into v3 first.

  • @hunterfox6230
    @hunterfox6230 8 месяцев назад

    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  8 месяцев назад +1

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

    • @hunterfox6230
      @hunterfox6230 8 месяцев назад

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

  • @andrewz8763
    @andrewz8763 4 месяца назад

    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  4 месяца назад +1

      🙂 I think so

    • @andrewz8763
      @andrewz8763 4 месяца назад

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

  • @LupoNoBrain
    @LupoNoBrain 8 месяцев назад

    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 8 месяцев назад

      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  8 месяцев назад

      😁 Glad you got it up and running!

  • @hunterfox6230
    @hunterfox6230 8 месяцев назад

    @ 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 8 месяцев назад

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

    • @LlamAcademy
      @LlamAcademy  8 месяцев назад +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 8 месяцев назад

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

  • @ZangJM
    @ZangJM 7 месяцев назад

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

    • @LlamAcademy
      @LlamAcademy  7 месяцев назад +1

      In this video around 08:09

  • @Hazzel31337
    @Hazzel31337 11 месяцев назад

    thanks verry complex, reminds me of the DOTS tutorial

  • @maximdaigle
    @maximdaigle 7 месяцев назад

    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  7 месяцев назад +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 7 месяцев назад

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

  • @jutekpixel
    @jutekpixel 7 месяцев назад

    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  7 месяцев назад +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 7 месяцев назад

      @@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 6 месяцев назад +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!

  • @hunterfox6230
    @hunterfox6230 8 месяцев назад

    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  8 месяцев назад

      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.

  • @yours_indie_game_dev
    @yours_indie_game_dev Год назад

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

    • @LlamAcademy
      @LlamAcademy  Год назад

      Yes of course you can use a Rigidbody as well 🙂

  • @PRodi_
    @PRodi_ Год назад

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

    • @LlamAcademy
      @LlamAcademy  Год назад +1

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

  • @Trinimp
    @Trinimp 11 месяцев назад

    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  11 месяцев назад +1

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

    • @Trinimp
      @Trinimp 11 месяцев назад

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

    • @Trinimp
      @Trinimp 11 месяцев назад

      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  11 месяцев назад +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 11 месяцев назад +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

  • @PodCast3_6_9
    @PodCast3_6_9 10 месяцев назад

    Bravo Proud ......

  • @ducnguyenzz
    @ducnguyenzz Год назад

    amazing

  • @3network983
    @3network983 Год назад

    thanks

  • @qwetzq9757
    @qwetzq9757 10 месяцев назад +4

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

    • @LlamAcademy
      @LlamAcademy  10 месяцев назад +1

      👍 at least one from me!

  • @Rizzmaster9001
    @Rizzmaster9001 10 месяцев назад +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 10 месяцев назад

      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  10 месяцев назад +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

  • @janowazir
    @janowazir Год назад

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

    • @Onyhh
      @Onyhh Год назад +1

      why would u want to do that?

    • @eatower2
      @eatower2 2 месяца назад

      Best thing I could say is have multiple children each with a tag that you want. Seems like there might be better ways to do things, but this could work.

  • @greenfoxgrasstail2534
    @greenfoxgrasstail2534 Год назад

    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  Год назад

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

    • @LlamAcademy
      @LlamAcademy  Год назад

      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 Год назад

      ​@@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 Год назад

      @@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 Год назад

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

  • @janowazir
    @janowazir Год назад

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

    • @LlamAcademy
      @LlamAcademy  Год назад

      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 Год назад

      @@LlamAcademy 👋But make a video about it

    • @5ld734
      @5ld734 10 месяцев назад

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

  • @criminalbotanist
    @criminalbotanist 6 месяцев назад

    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: ruclips.net/video/oDGgwKKGIpg/видео.html

    • @LlamAcademy
      @LlamAcademy  6 месяцев назад

      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! :)

  • @rbr0319
    @rbr0319 7 месяцев назад

    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  7 месяцев назад

      The only Discord I have is exclusive for RUclips members / Patreon supporters.