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

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

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

  • @LlamAcademy
    @LlamAcademy  8 หลายเดือนก่อน +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: th-cam.com/video/3PLDIEjmQsI/w-d-xo.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: th-cam.com/video/5uO0dXYbL-s/w-d-xo.html
    ⚫ Dependency Injection: en.wikipedia.org/wiki/Dependency_injection
    ⚫ Which AI Behavior Framework Should You Use? th-cam.com/video/CZvfuNfdc1M/w-d-xo.html

  • @CrashKonijn
    @CrashKonijn 8 หลายเดือนก่อน +16

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

    • @LlamAcademy
      @LlamAcademy  8 หลายเดือนก่อน +6

      Thanks for all your work on the system 🧡!

    • @Michael-es6qw
      @Michael-es6qw 8 หลายเดือนก่อน

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

    • @greenfoxgrasstail2534
      @greenfoxgrasstail2534 8 หลายเดือนก่อน +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 4 หลายเดือนก่อน +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  4 หลายเดือนก่อน

      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 😋

  • @evanciao
    @evanciao 8 หลายเดือนก่อน +1

    Finally! Thank you so much for creating this tutorial!

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

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

  • @alec_almartson
    @alec_almartson 8 หลายเดือนก่อน +2

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

  • @kronusbr17
    @kronusbr17 8 หลายเดือนก่อน +1

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

  • @qwetzq9757
    @qwetzq9757 6 หลายเดือนก่อน +4

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

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

      👍 at least one from me!

  • @Hazzel31337
    @Hazzel31337 6 หลายเดือนก่อน

    thanks verry complex, reminds me of the DOTS tutorial

  • @andrewz8763
    @andrewz8763 16 วันที่ผ่านมา

    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  11 วันที่ผ่านมา +1

      🙂 I think so

    • @andrewz8763
      @andrewz8763 11 วันที่ผ่านมา

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

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

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

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

  • @O2Dev
    @O2Dev 8 หลายเดือนก่อน +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  8 หลายเดือนก่อน +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

  • @Damian_h
    @Damian_h 8 หลายเดือนก่อน +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 5 หลายเดือนก่อน

      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

  • @usercontent2112
    @usercontent2112 8 หลายเดือนก่อน

    Epic intro!

    • @usercontent2112
      @usercontent2112 8 หลายเดือนก่อน

      Thank you for explaining in details about GOAP!

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

      💪 thanks 😊

  • @bluzenkk
    @bluzenkk 8 หลายเดือนก่อน +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 8 หลายเดือนก่อน +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  8 หลายเดือนก่อน +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.

    • @user-ws7ub3kt4r
      @user-ws7ub3kt4r 6 หลายเดือนก่อน

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

    • @CrashKonijn
      @CrashKonijn 6 หลายเดือนก่อน

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

    • @user-ws7ub3kt4r
      @user-ws7ub3kt4r 6 หลายเดือนก่อน

      Okay, I understand, thanks

  • @hunterfox6230
    @hunterfox6230 4 หลายเดือนก่อน

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

      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.

  • @PodCast3_6_9
    @PodCast3_6_9 6 หลายเดือนก่อน

    Bravo Proud ......

  • @ducnguyenzz
    @ducnguyenzz 8 หลายเดือนก่อน

    amazing

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

      🧡 thank you

  • @user-ws7ub3kt4r
    @user-ws7ub3kt4r 6 หลายเดือนก่อน +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?

    • @user-ws7ub3kt4r
      @user-ws7ub3kt4r 6 หลายเดือนก่อน

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

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

      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 🙂

    • @user-ws7ub3kt4r
      @user-ws7ub3kt4r 5 หลายเดือนก่อน

      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

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

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

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

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

    thanks

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

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

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

      In this video around 08:09

  • @hunterfox6230
    @hunterfox6230 4 หลายเดือนก่อน

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

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

    • @hunterfox6230
      @hunterfox6230 4 หลายเดือนก่อน

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

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

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

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

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

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

    • @LlamAcademy
      @LlamAcademy  4 หลายเดือนก่อน +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 4 หลายเดือนก่อน

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

  • @LupoNoBrain
    @LupoNoBrain 4 หลายเดือนก่อน

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

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

      😁 Glad you got it up and running!

  • @yours_indie_game_dev
    @yours_indie_game_dev 8 หลายเดือนก่อน

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

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

      Yes of course you can use a Rigidbody as well 🙂

  • @PRodi_
    @PRodi_ 8 หลายเดือนก่อน

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

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

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

  • @Trinimp
    @Trinimp 6 หลายเดือนก่อน

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

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

    • @Trinimp
      @Trinimp 6 หลายเดือนก่อน

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

    • @Trinimp
      @Trinimp 6 หลายเดือนก่อน

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

  • @janowazir
    @janowazir 8 หลายเดือนก่อน

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

    • @Onyhh
      @Onyhh 8 หลายเดือนก่อน +1

      why would u want to do that?

  • @greenfoxgrasstail2534
    @greenfoxgrasstail2534 8 หลายเดือนก่อน

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

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

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

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

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

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

      nvm ....there it is. Showed up ... after i posted something else. TH-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...

  • @frediwalker2381
    @frediwalker2381 6 หลายเดือนก่อน +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 6 หลายเดือนก่อน

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

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

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

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

      @@LlamAcademy 👋But make a video about it

    • @5ld734
      @5ld734 5 หลายเดือนก่อน

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

    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: th-cam.com/video/oDGgwKKGIpg/w-d-xo.html

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

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

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

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