How to code SMARTER A.I. enemies | Unity Tutorial

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

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

  • @this-is-gamedev
    @this-is-gamedev  ปีที่แล้ว +11

    I realised that I had modified the StateMachine class and added a GetGizmoColor that I don't show in the video. This to make it easier to debug, so do as you please. Here is the code that would go into StateMachine.cs:
    public Color GetGizmoColor() {
    if (currentState != null) {
    return currentState.GizmoColor();
    }
    return Color.grey;
    }

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

      please help
      NullReferenceException: Object reference not set to an instance of an object
      EnemyState_RunToCover.OnEnter () (at Assets/Enemy/Enemy Scripts/EnemyState_RunToCover.cs:20)
      StateMachine.SetState (IState state) (at Assets/Enemy/Enemy Scripts/StateMachine.cs:36)
      EnemyBrainV2.Start () (at Assets/Enemy/Enemy Scripts/EnemyBrainV2.cs:32)
      ive followed yout tutorial till the 27 min mark and have ebeen stuck sorting out errors for about 8 hours now finnaly down to 1 and i cant understand as to why im getting this problem i have done everything you have mentioned but yet still no progress

    • @this-is-gamedev
      @this-is-gamedev  ปีที่แล้ว

      @@REALHARIBO the issue here is a reference is null, so either a variables os not initialised or you did not link all the things in the editor.
      My guess from your error pasted, is the CoverArea is null but could be something else

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

      You need to drag CoverArea Script to 'Covers' GameObject in hierarchy@@REALHARIBO

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

      @@REALHARIBO I Guess stateMachine = new StateMachine(); is to be initialized in RunToCover State

  • @cmvr1003
    @cmvr1003 4 หลายเดือนก่อน +3

    As someone who's been self teaching game dev as a hobby it's really refreshing to find content that focuses on not just how to achieve a result, or implement something in the most basic sense, but instead focus on how to achieve a result that's good, or implement a feature with polish. I'm pretty sure i've learnt most of the basic implementation methods, so thank you so much for taking the time to create such high quality videos that are for a more intermediate/advanced audience.

    • @this-is-gamedev
      @this-is-gamedev  4 หลายเดือนก่อน +3

      Hey thanks! Appreciate it!

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

      Great comment, I feel the same way. I learned a lot, thanks!

  • @armandopaez8882
    @armandopaez8882 ปีที่แล้ว +7

    Definitely worth the length of the video. Your way of explaining is simply wonderful. It's almost like going to school. Thanks, master!

  • @l.halawani
    @l.halawani 7 หลายเดือนก่อน +1

    This is a really high quality content, not only is everything explained really well theoretically and demonstrated practically, but also you leave us with specific keywords to find out more where relevant. Feels like a paid course, and a good one on that note.

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

    My gawd, i finnaly found this, this is exactly what i needed for my game. Thank you for explaining this in such a basic level, that even i could understand! Big up!

  • @mook_10
    @mook_10 ปีที่แล้ว +16

    this is exactly what i was looking for. please please please make more. SO many tutorials on here covering the "stupid" AIs but really nothing covering enemies who even pretend to have a sense of strategy

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

    you are not a live saver, you are the embodiment of divine intervention. i was looking to pick up unity to develop a payday 2 type game, where the ai bassicaly just throws itself at the player. you cant even imagine how many tutorials ive watched to try and find what i need. thanks so much man

    • @this-is-gamedev
      @this-is-gamedev  ปีที่แล้ว

      You’re welcome :D I am happy it’s helpful :D

  • @travisgarrisonihdlive
    @travisgarrisonihdlive ปีที่แล้ว +5

    Great tutorial but one thing I did find an issue with after adding more then one ai you have to do a check if the cover is taken or not or the ai will trip out trying to get in the same position as another. After adding a check for this it worked perfectly.

    • @this-is-gamedev
      @this-is-gamedev  ปีที่แล้ว +1

      Yes, with more than one, you probably want a manager / commander that will tell where each agent should go. That can then also be a statemachine with different strategies etc based on the player’s actions :D

  • @MattMurphy-e2g
    @MattMurphy-e2g 7 หลายเดือนก่อน +1

    Just an FYI. NavMesh 'Helping an enemy find its way to its destination without running into anything' is using an A* algorithm.... which is actually one of the first Ai algorithms people learn.

    • @l.halawani
      @l.halawani 7 หลายเดือนก่อน

      It's more ML than AI, not all ML is AI

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

    I just want to say thank you. It is kind of advanced topic and not for my beginner level but I didn't see anyone explain it in your way or event hight light some of these advanced topics. Even if I didn't understand everything I still find it useful and helpful.

    • @this-is-gamedev
      @this-is-gamedev  10 หลายเดือนก่อน

      I happy you find it useful! Give it some time and try to use it in a simple way like just 2-3 states to get started.

  • @senorcarlito-6119
    @senorcarlito-6119 3 หลายเดือนก่อน

    Thank you for the wonderful explanation, as someone who is eager to get into AI, this is extremely helpful.

    • @this-is-gamedev
      @this-is-gamedev  3 หลายเดือนก่อน

      Awesome! There is a lot to learn in this subject! Happy if this hells you start!

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

    Vastly useful!.. many thanks for the info.. I needed this to progress :D

    • @this-is-gamedev
      @this-is-gamedev  2 หลายเดือนก่อน +1

      Awesome! Good to hear!

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

    Fuck you for being late to post this on the internet 😂.
    No cap this is *THE* thing i was looking for 1.5+ years, this tutorial is a hidden gem ❤. you earned a subscriber

    • @this-is-gamedev
      @this-is-gamedev  ปีที่แล้ว +1

      Haha, that’s awesome. I am happy it’s helpful :D

  • @강성원-i5o
    @강성원-i5o 8 หลายเดือนก่อน

    프로젝트에서 적을 구현하는 것에 큰 도움이 됐습니다. 감사합니다.

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

    Rockstar must hire this guys.. for the next evolve game think..

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

    Uhhh, He called me dedicated... I'm touched🥺!

  • @ShyVortexYT
    @ShyVortexYT 4 หลายเดือนก่อน +1

    I've followed through everything but I run into an issue at the very end, it works but the target's position isn't updated every tick like one would expect. If I move around the agent keeps shooting at my initial position

  • @this-is-gamedev
    @this-is-gamedev  ปีที่แล้ว +8

    The video became a bit long. I usually aim for 10 minutes. Anyway, I hope you enjoy and let me know what you like and what you hate. I have many more tutorials in the pipeline :D

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

      Thanks for the class

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

      I was wondering, without access to editable scripts or ability to use new scripts... Is there any way we can use ultimate events to make them seem smarter or exhibit new behaviors?

    • @this-is-gamedev
      @this-is-gamedev  ปีที่แล้ว

      Event system can help yes, but you will need to write some code, at least to raise the events at the right moment.

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

      @@this-is-gamedev Alright. Thank you. The reason I was asking is I'm trying to get some desirable behaviors out of the AI in Bonelab, but those developers thought it was a great idea to not permit their edited SDK for unity and their game to use scripts that weren't included in the base game, so most of us are stuck trying to force ult events to do things that it wasn't meant to do. Technically we do have their base scripts, but no access to see what is inside of them.

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

    This was really informative. Thanks man.

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

    Overall a useful tutorial- but it would have been better to see it more compartmentalized. Adding all the animations and such in complicates what was the interesting part of the video which is the enemies behavior.

    • @this-is-gamedev
      @this-is-gamedev  ปีที่แล้ว +1

      Thanks! That’s true. I’ll see what I can do. Could make another video showing different use cases and just focusing the FSM

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

      @@this-is-gamedev for sure! I mean no shade, I don’t have the courage to post videos so either way - it’s your style! I’ve been a dev for a while now but newer to C# and Unity - and I’ve always personally preferred highly specific videos as gluing the pieces together usually isn’t too bad once you know how the individual pieces work. But that’s just me and I know I don’t speak for everyone. Was a very useful video overall

    • @this-is-gamedev
      @this-is-gamedev  ปีที่แล้ว

      @@squirrelzarNo worries. I am listening to all feedback and ideas. :D

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

    Thank you. This is what I am looking for.

  • @санитарпсихбольницы
    @санитарпсихбольницы ปีที่แล้ว

    12:03 - genius mem

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

    High quality!

  • @am-apps-games
    @am-apps-games ปีที่แล้ว +1

    Very well done! Thank you

  • @Abdullahkhan-lk5zl
    @Abdullahkhan-lk5zl 11 หลายเดือนก่อน

    Hey man, GREAT Video. Where can i get your code.

  • @MotabhaiOp-u8g
    @MotabhaiOp-u8g 7 หลายเดือนก่อน

    Amazing tutorial i just ran into a problem my enemy is reloading but the ducking animation is not playing along with the reloading animation

    • @this-is-gamedev
      @this-is-gamedev  7 หลายเดือนก่อน

      Thanks! To play both, you need to split them on 2 animation layers and setup the avatar to mask the bones for the second layer

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

    Great tutorial , thanks 🎉

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

    Thanks for making tutorial for noob like me! :D

  • @androvictrayo-dy7eh
    @androvictrayo-dy7eh ปีที่แล้ว

    This is a fantastic tutorial

  • @everythingcouldbesimplify818
    @everythingcouldbesimplify818 ปีที่แล้ว +4

    Learn Animancer and you will never want to look back to animator ever again

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

    Hey! Great Video but when using this in my schoolprojekt i've run into some troubles. In my scene everything works just fine but as soon as i put the enemys into the main scene they move around for no reason at all. Even when put in the coverstate from the beginnig on they start spinning and moveing around the map. Is there any way you could help me out with this problem?

    • @this-is-gamedev
      @this-is-gamedev  ปีที่แล้ว

      Hi, thanks! Difficult to say what is the cause, is it maybe a loose rigidbody?

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

    hey man great tutorial i just ran into this error that my trail render is visible but they tend to go downward rather than following the ray they tend to go to the bottom of the player

    • @this-is-gamedev
      @this-is-gamedev  7 หลายเดือนก่อน

      Thanks!
      Mmm, this might be some pivot issue

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

      @@this-is-gamedevthanks man I already solved it it was a code issue

  • @NeonDev-n7t
    @NeonDev-n7t 4 หลายเดือนก่อน

    3:01 if it blue it good got me so hard 😂😂😂😂 ( btw i really liked the way that he speaks and it is understandable course also he's really cute (i am not gay just being honest) )

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

    Just Amazing

  • @President_PunchLines
    @President_PunchLines 7 หลายเดือนก่อน +1

    Hey man I ran into this new issue, the code error says there is nothing called func for statemachine and also I am getting a new error it says that statemachine don't have get gizmos color function, how can I solve it

    • @this-is-gamedev
      @this-is-gamedev  7 หลายเดือนก่อน

      The gizmo thing can be added, it was an example. The code is in the pinned comment.

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

      Thanks

    • @gussothe2nd
      @gussothe2nd 15 วันที่ผ่านมา

      Did you ever solve the other issue with the func? I'm currently stuck here too

  • @6Abdellah9
    @6Abdellah9 ปีที่แล้ว

    thx so much, ur a life saver im using this for a school project, however I came across a little bug start reload gets called but it never reloads any idea why and do u have the scripts anywhere so I can better see the difference

    • @this-is-gamedev
      @this-is-gamedev  ปีที่แล้ว

      It might be that the Reload layer on the animator does not have the weight to 1. Or that the transition is not well configured.

    • @6Abdellah9
      @6Abdellah9 ปีที่แล้ว

      @@this-is-gamedev yes that was it thx

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

    Thanks!

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

    What should I do, if I have a big open world? Or I can do the same stuff?

    • @this-is-gamedev
      @this-is-gamedev  ปีที่แล้ว +1

      Usually, the enemies act local to a part of the world. You can’t really have tons of enemies active at ones. Or you can. You might have to look into ECS maybe or other ways to manage open world games. But state machine can be used for everything, yes :D

  • @mamad-b2s
    @mamad-b2s ปีที่แล้ว

    Very good but I can't add nav mesh because I haven't AI in my Unity
    What's your version of Unity
    Is it possible with version (2022 ,personal)?

    • @this-is-gamedev
      @this-is-gamedev  ปีที่แล้ว

      I missed that news with 2022. It seems you have to installed from the package manager. It should be called “AI Navigation”

    • @mamad-b2s
      @mamad-b2s ปีที่แล้ว +1

      ​@@this-is-gamedev
      Thank you so much..❤
      Im from Iran, and there is no one to ask him, and I get lost

  • @technicalm.t.b5251
    @technicalm.t.b5251 7 หลายเดือนก่อน +1

    Sir you Dummie character is not showing in scene and also on demo and also when pick it up from models to in heirarchy still just showing colliders

  • @technicalm.t.b5251
    @technicalm.t.b5251 7 หลายเดือนก่อน

    my enemy not following my player there are no errors on console why it just happened to me :"(( i checked everything is correct i have also added player in enemy target and my player has collider so now what should i do, i have created a empty game object in hierarchy and added navmeshsurface component in and i baked and after that everything just fine just like your and i got a problem after backed navmesh detect my player as a obsticles and made border around my player just like other object and i solve by adding layer mask as player and navmesh ignore that it fixed bu still not following enemy my player at 11:46 ?

  • @Johnny-Wayfinder
    @Johnny-Wayfinder 4 หลายเดือนก่อน

    The word you're looking for is "Navigable".

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

    I don't know what I did but I'm having problems with the project, from EnemyBrain_Smart to EnemyState_Delay, one tells me it's StateMachine and the other is IState, I really needed a little help starts in 25:19 please i need help

    • @this-is-gamedev
      @this-is-gamedev  11 หลายเดือนก่อน

      EnemyBrain_Smart has the state machine inside. You can’t use a transition -> you have to ->

  • @ZeldaGamesForever
    @ZeldaGamesForever 19 นาทีที่ผ่านมา

    Please, I need help:
    I have 3 errors in the EnemyState_Cover.
    Assets/Scripts/EnemyState_Cover.cs(4,33): error CS0535: 'EnemyState_Cover' does not implement interface member 'IState.Tick()'
    Assets/Scripts/EnemyState_Cover.cs(4,33): error CS0535: 'EnemyState_Cover' does not implement interface member 'IState.OnEnter()'
    Assets/Scripts/EnemyState_Cover.cs(4,33): error CS0535: 'EnemyState_Cover' does not implement interface member 'IState.OnExit()'

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

    Does it still work? I can only bak the Mesh in "Navigation Obsolete
    "

    • @this-is-gamedev
      @this-is-gamedev  7 หลายเดือนก่อน

      Yes, just the AI navigation is now a unity package. But its API is the same.

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

      Ok thx

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

    is there a way to add a "patrol function"? i tried everything but it eighter ignores it or the code breaks

    • @this-is-gamedev
      @this-is-gamedev  ปีที่แล้ว

      Yes, you have to create a new script that implements IState and then where the state machine is create, you create a new instance of your state and make sure it is either the starting state or you transition to that state.

  • @RSilva-ic8qv
    @RSilva-ic8qv ปีที่แล้ว

    hello , can you help me ? i cant find the link for the bullet tracer ...

    • @this-is-gamedev
      @this-is-gamedev  ปีที่แล้ว

      Search “liamacademy bullet” it’s the first hit.

    • @RSilva-ic8qv
      @RSilva-ic8qv 10 หลายเดือนก่อน

      ty:)
      @@this-is-gamedev

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

    Will this work with multiplayer like photon

    • @this-is-gamedev
      @this-is-gamedev  ปีที่แล้ว

      Yes. But I am not that familiar with photon, so you have to just intergrate it with whatever photon uses to sync data across clients

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

    bro do u know how to implement G.O.A.P? for enemy or bosses

    • @this-is-gamedev
      @this-is-gamedev  11 หลายเดือนก่อน

      Didn’t touch GOAP, yet. It’s a lot of work and ideally you will need some custom tools to debug everything, since enemies are a kind of “free”

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

      @@this-is-gamedev Jesus christ man im just an artist trying to survive programming subjects but the things they ask sometimes are ridiculously difficult.
      BTW Great video super interesting!

    • @this-is-gamedev
      @this-is-gamedev  11 หลายเดือนก่อน +1

      Oh wow. Check LliamAcademy, he has a good series on GOAP

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

      @@this-is-gamedev Will do asap bro thanks a lot.

  • @mamad-b2s
    @mamad-b2s ปีที่แล้ว

    What is your version of Unity? I am using Unity version (2022, personal) I don't have AI please help me

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

      On unity 2022.2+ you need to install AI navigation package from the package manager.

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

    How do I make it so the enemy can kill the player?

    • @this-is-gamedev
      @this-is-gamedev  2 หลายเดือนก่อน +1

      The player needs a health script that detect the bullet hitting them (physical collision) or the enemy tells the player “I hit you” via raycasts

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

      @@this-is-gamedev thanks!

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

    would any of this work/apply in a VRChat world?

    • @this-is-gamedev
      @this-is-gamedev  ปีที่แล้ว

      If you can write code, you can write state machines

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

    onto my 30th time watching the vid done everything but for some reason the states stop switching after going grey 😥

    • @this-is-gamedev
      @this-is-gamedev  ปีที่แล้ว

      Mmmm, add some Debug.Log to be sure that 1) all states enter and exit correctly 2) monitor the values that are used to transition from 1 state to another

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

      @@this-is-gamedev heres my enemy cover script i think it is the main problem as i am getting an error that The local function 'Any' is declared but never used using System;
      using System.Collections.Generic;
      using UnityEngine;
      public class EnemyCover : IState
      {
      private EnemyReferences enemyReferences;
      private StateMachine stateMachine;
      public EnemyCover(EnemyReferences enemyReferences)
      {
      this.enemyReferences = enemyReferences;
      stateMachine = new StateMachine();
      // STATES
      var enemyShoot = new EnemyShootState(enemyReferences);
      var enemyDelay = new Delay(1f);
      var enemyReload = new EnemyReloadState(enemyReferences);
      // TRANSITIONS
      At(enemyShoot, enemyReload, () => enemyReferences.shooter.ShouldReload());
      At(enemyReload, enemyDelay, () => !enemyReferences.shooter.ShouldReload());
      At(enemyDelay, enemyShoot, () => enemyDelay.IsDone());
      // STARTSTATE
      stateMachine.SetState(enemyShoot);
      // FUNCTIONS & CONDITIONS
      void At(IState from, IState to, Func condition) => stateMachine.AddTransition(from, to, condition);
      void Any(IState to, Func condition) => stateMachine.AddAnyTransition(to, condition);
      }

      public void OnEnter()
      {
      enemyReferences.animator.SetBool("combat", true);
      }
      public void OnExit()
      {
      enemyReferences.animator.SetBool("combat", false);
      }
      public void Tick()
      {
      stateMachine.Tick();
      }
      public Color GizmoColor()
      {
      return stateMachine.GetGizmoColor();
      }
      }

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

      @@this-is-gamedev please help bro

    • @this-is-gamedev
      @this-is-gamedev  ปีที่แล้ว

      Looks correct. Are you sure the animator is correctly setup? That all parameters match. lowercase and uppercase is important

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

      @@this-is-gamedev yeah it was that i forgot to actually start the reload function when the ammo was empty but thx

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

    Great Video But, that yellow background makes people blind... 😵😵😵😵

    • @this-is-gamedev
      @this-is-gamedev  4 หลายเดือนก่อน

      Thanks. First time I get this feedback! It’s a fair point :D

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

    Smarter every day reference?)

    • @this-is-gamedev
      @this-is-gamedev  8 หลายเดือนก่อน +1

      If that’s the case, not done on purpose 😌

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

    merci frerooo

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

    dunno why but my transitions not work

    • @this-is-gamedev
      @this-is-gamedev  ปีที่แล้ว

      Check the conditions and check that when you call methods on the animator that the strings match 1 to 1. It is case sensitive

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

      @@this-is-gamedev thanks for help u got one sub from me :)