No video

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

  Рет қаралды 52,958

This is GameDev

This is GameDev

Күн бұрын

Пікірлер: 116
@this-is-gamedev
@this-is-gamedev Жыл бұрын
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 10 ай бұрын
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 10 ай бұрын
@@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 9 ай бұрын
You need to drag CoverArea Script to 'Covers' GameObject in hierarchy@@REALHARIBO
@rock8science
@rock8science 5 ай бұрын
@@REALHARIBO I Guess stateMachine = new StateMachine(); is to be initialized in RunToCover State
@cmvr1003
@cmvr1003 Ай бұрын
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 Ай бұрын
Hey thanks! Appreciate it!
@mook_10
@mook_10 Жыл бұрын
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
@this-is-gamedev
@this-is-gamedev Жыл бұрын
Thanks! That’s the plan :D
@l.halawani
@l.halawani 4 ай бұрын
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.
@armandopaez8882
@armandopaez8882 Жыл бұрын
Definitely worth the length of the video. Your way of explaining is simply wonderful. It's almost like going to school. Thanks, master!
@this-is-gamedev
@this-is-gamedev Жыл бұрын
Thanks Appreciate it! 🤓
@halivudestevez2
@halivudestevez2 2 ай бұрын
better than school :)
@gun8737
@gun8737 Жыл бұрын
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
@senorcarlito-6119
@senorcarlito-6119 24 күн бұрын
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 15 күн бұрын
Awesome! There is a lot to learn in this subject! Happy if this hells you start!
@this-is-gamedev
@this-is-gamedev Жыл бұрын
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.
@ahmaddalao
@ahmaddalao 7 ай бұрын
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 7 ай бұрын
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.
@travisgarrisonihdlive
@travisgarrisonihdlive Жыл бұрын
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 Жыл бұрын
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
@user-fz4er7yi9y
@user-fz4er7yi9y 5 ай бұрын
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 4 ай бұрын
It's more ML than AI, not all ML is AI
@user-cs5hv7rb8n
@user-cs5hv7rb8n 5 ай бұрын
프로젝트에서 적을 구현하는 것에 큰 도움이 됐습니다. 감사합니다.
@kalpolproductions8558
@kalpolproductions8558 Жыл бұрын
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 Жыл бұрын
Haha, that’s awesome. I am happy it’s helpful :D
@ShyVortexYT
@ShyVortexYT 2 ай бұрын
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
@DionteHelm
@DionteHelm 9 ай бұрын
This was really informative. Thanks man.
@this-is-gamedev
@this-is-gamedev 9 ай бұрын
Thanks!
@am-apps-games
@am-apps-games Жыл бұрын
Very well done! Thank you
@this-is-gamedev
@this-is-gamedev Жыл бұрын
Thanks! I am glad you like it!
@Ranger8744
@Ranger8744 24 күн бұрын
Uhhh, He called me dedicated... I'm touched🥺!
@OrdeBaruMilenial
@OrdeBaruMilenial 5 ай бұрын
Rockstar must hire this guys.. for the next evolve game think..
@venkatswaraj3054
@venkatswaraj3054 Жыл бұрын
Thank you. This is what I am looking for.
@this-is-gamedev
@this-is-gamedev Жыл бұрын
Nice! Happy it’s helpful :)
@sklintergames6662
@sklintergames6662 9 ай бұрын
Great tutorial , thanks 🎉
@this-is-gamedev
@this-is-gamedev 9 ай бұрын
Thanks! 🙏
@thebestcelep6358
@thebestcelep6358 Жыл бұрын
High quality!
@androvictrayo-dy7eh
@androvictrayo-dy7eh Жыл бұрын
This is a fantastic tutorial
@this-is-gamedev
@this-is-gamedev Жыл бұрын
Thanks! Happy you like it!
@squirrelzar
@squirrelzar 10 ай бұрын
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 10 ай бұрын
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 10 ай бұрын
@@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 10 ай бұрын
@@squirrelzarNo worries. I am listening to all feedback and ideas. :D
@technicalm.t.b5251
@technicalm.t.b5251 4 ай бұрын
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
@user-dc2qk9hh3x
@user-dc2qk9hh3x 10 ай бұрын
12:03 - genius mem
@muhammadzubairirshad6724
@muhammadzubairirshad6724 5 ай бұрын
Just Amazing
@user-wk5hr1vx1g
@user-wk5hr1vx1g Ай бұрын
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) )
@everythingcouldbesimplify818
@everythingcouldbesimplify818 Жыл бұрын
Learn Animancer and you will never want to look back to animator ever again
@this-is-gamedev
@this-is-gamedev Жыл бұрын
I’ll take a look. Thanks!
@LagowiecDev
@LagowiecDev Жыл бұрын
Thanks for making tutorial for noob like me! :D
@flixlcookie8222
@flixlcookie8222 9 ай бұрын
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 9 ай бұрын
Hi, thanks! Difficult to say what is the cause, is it maybe a loose rigidbody?
@President_PunchLines
@President_PunchLines 5 ай бұрын
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 5 ай бұрын
Thanks! Mmm, this might be some pivot issue
@President_PunchLines
@President_PunchLines 5 ай бұрын
@@this-is-gamedevthanks man I already solved it it was a code issue
@technicalm.t.b5251
@technicalm.t.b5251 4 ай бұрын
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 ?
@user-ur3cw2bf9s
@user-ur3cw2bf9s 4 ай бұрын
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 4 ай бұрын
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
@havoc-blaze
@havoc-blaze Ай бұрын
The word you're looking for is "Navigable".
@President_PunchLines
@President_PunchLines 5 ай бұрын
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 4 ай бұрын
The gizmo thing can be added, it was an example. The code is in the pinned comment.
@President_PunchLines
@President_PunchLines 4 ай бұрын
Thanks
@Linguin_
@Linguin_ 4 ай бұрын
Does it still work? I can only bak the Mesh in "Navigation Obsolete "
@this-is-gamedev
@this-is-gamedev 4 ай бұрын
Yes, just the AI navigation is now a unity package. But its API is the same.
@Linguin_
@Linguin_ 4 ай бұрын
Ok thx
@praisethesun2612
@praisethesun2612 10 ай бұрын
Thanks!
@this-is-gamedev
@this-is-gamedev 10 ай бұрын
You’re welcome :D
@Abdullahkhan-lk5zl
@Abdullahkhan-lk5zl 8 ай бұрын
Hey man, GREAT Video. Where can i get your code.
@ruisilva59
@ruisilva59 8 ай бұрын
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 8 ай бұрын
EnemyBrain_Smart has the state machine inside. You can’t use a transition -> you have to ->
@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.
@iliagusarov8662
@iliagusarov8662 9 ай бұрын
What should I do, if I have a big open world? Or I can do the same stuff?
@this-is-gamedev
@this-is-gamedev 9 ай бұрын
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
@user-dw5ku8bq3z
@user-dw5ku8bq3z Жыл бұрын
What is your version of Unity? I am using Unity version (2022, personal) I don't have AI please help me
@poonamagrawal4472
@poonamagrawal4472 11 ай бұрын
On unity 2022.2+ you need to install AI navigation package from the package manager.
@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
@LION303200
@LION303200 Ай бұрын
Great Video But, that yellow background makes people blind... 😵😵😵😵
@this-is-gamedev
@this-is-gamedev Ай бұрын
Thanks. First time I get this feedback! It’s a fair point :D
@RSilva-ic8qv
@RSilva-ic8qv 10 ай бұрын
hello , can you help me ? i cant find the link for the bullet tracer ...
@this-is-gamedev
@this-is-gamedev 10 ай бұрын
Search “liamacademy bullet” it’s the first hit.
@RSilva-ic8qv
@RSilva-ic8qv 7 ай бұрын
ty:) @@this-is-gamedev
@afrodidcraft
@afrodidcraft Жыл бұрын
merci frerooo
@this-is-gamedev
@this-is-gamedev Жыл бұрын
De rien 😉
@user-dw5ku8bq3z
@user-dw5ku8bq3z Жыл бұрын
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”
@user-dw5ku8bq3z
@user-dw5ku8bq3z Жыл бұрын
​@@this-is-gamedev Thank you so much..❤ Im from Iran, and there is no one to ask him, and I get lost
@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
@cosmotect
@cosmotect 5 ай бұрын
Smarter every day reference?)
@this-is-gamedev
@this-is-gamedev 5 ай бұрын
If that’s the case, not done on purpose 😌
@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
@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 Жыл бұрын
@@this-is-gamedev yeah it was that i forgot to actually start the reload function when the ammo was empty but thx
@Damian_h
@Damian_h 8 ай бұрын
bro do u know how to implement G.O.A.P? for enemy or bosses
@this-is-gamedev
@this-is-gamedev 8 ай бұрын
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_h
@Damian_h 8 ай бұрын
@@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 8 ай бұрын
Oh wow. Check LliamAcademy, he has a good series on GOAP
@Damian_h
@Damian_h 8 ай бұрын
@@this-is-gamedev Will do asap bro thanks a lot.
@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 :)
Ranking ALL Design Patterns for Games under 30min
25:51
This is GameDev
Рет қаралды 8 М.
Which AI Behavior Framework Should You Use? | AI Series 46
17:26
LlamAcademy
Рет қаралды 43 М.
女孩妒忌小丑女? #小丑#shorts
00:34
好人小丑
Рет қаралды 83 МЛН
Can This Bubble Save My Life? 😱
00:55
Topper Guild
Рет қаралды 84 МЛН
What will he say ? 😱 #smarthome #cleaning #homecleaning #gadgets
01:00
The Trick I Used to Make Combat Fun! | Devlog
8:12
Game Endeavor
Рет қаралды 1,6 МЛН
20 Advanced Coding Tips For Big Unity Projects
22:23
Tesseract
Рет қаралды 178 М.
How to code Coilhead from Lethal Company - Unity Tutorial
11:53
2D PATHFINDING - Enemy AI in Unity
23:13
Brackeys
Рет қаралды 812 М.
134 Unity Components EXPLAINED in Less than 30 Minutes
24:01
This is GameDev
Рет қаралды 61 М.
How To Make UIs without frustration | Unity Beginner Tutorial
16:58
This is GameDev
Рет қаралды 31 М.
Giving Personality to Procedural Animations using Math
15:30
t3ssel8r
Рет қаралды 2,5 МЛН
How to Make a Good 2D Camera
11:38
Game Maker's Toolkit
Рет қаралды 400 М.
How to ACTUALLY get into Gamedev
14:01
DaFluffyPotato
Рет қаралды 718 М.
女孩妒忌小丑女? #小丑#shorts
00:34
好人小丑
Рет қаралды 83 МЛН