Тёмный

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

This is GameDev
Подписаться 8 тыс.
Просмотров 56 тыс.
0% 0

Опубликовано:

 

29 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 122   
@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 11 месяцев назад
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 11 месяцев назад
@@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 10 месяцев назад
You need to drag CoverArea Script to 'Covers' GameObject in hierarchy@@REALHARIBO
@rock8science
@rock8science 6 месяцев назад
@@REALHARIBO I Guess stateMachine = new StateMachine(); is to be initialized in RunToCover State
@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 5 месяцев назад
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.
@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.
@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
@ShyVortexYT
@ShyVortexYT 3 месяца назад
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
@flixlcookie8222
@flixlcookie8222 11 месяцев назад
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 11 месяцев назад
Hi, thanks! Difficult to say what is the cause, is it maybe a loose rigidbody?
@President_PunchLines
@President_PunchLines 6 месяцев назад
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 6 месяцев назад
The gizmo thing can be added, it was an example. The code is in the pinned comment.
@President_PunchLines
@President_PunchLines 6 месяцев назад
Thanks
@NeonDev-n7t
@NeonDev-n7t 2 месяца назад
<a href="#" class="seekto" data-time="181">3:01</a> 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) )
@praisethesun2612
@praisethesun2612 11 месяцев назад
Thanks!
@this-is-gamedev
@this-is-gamedev 11 месяцев назад
You’re welcome :D
@havoc-blaze
@havoc-blaze 3 месяца назад
The word you're looking for is "Navigable".
@RSilva-ic8qv
@RSilva-ic8qv 11 месяцев назад
hello , can you help me ? i cant find the link for the bullet tracer ...
@this-is-gamedev
@this-is-gamedev 11 месяцев назад
Search “liamacademy bullet” it’s the first hit.
@RSilva-ic8qv
@RSilva-ic8qv 8 месяцев назад
ty:) @@this-is-gamedev
@Damian_h
@Damian_h 9 месяцев назад
bro do u know how to implement G.O.A.P? for enemy or bosses
@this-is-gamedev
@this-is-gamedev 9 месяцев назад
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 9 месяцев назад
@@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 9 месяцев назад
Oh wow. Check LliamAcademy, he has a good series on GOAP
@Damian_h
@Damian_h 9 месяцев назад
@@this-is-gamedev Will do asap bro thanks a lot.
@cmvr1003
@cmvr1003 2 месяца назад
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 2 месяца назад
Hey thanks! Appreciate it!
@falconegaming
@falconegaming 29 дней назад
Great comment, I feel the same way. I learned a lot, thanks!
@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 3 месяца назад
better than school :)
@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!
@technicalm.t.b5251
@technicalm.t.b5251 6 месяцев назад
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
@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
@LION303200
@LION303200 2 месяца назад
Great Video But, that yellow background makes people blind... 😵😵😵😵
@this-is-gamedev
@this-is-gamedev 2 месяца назад
Thanks. First time I get this feedback! It’s a fair point :D
@SilvintGamingStudios
@SilvintGamingStudios 19 дней назад
Vastly useful!.. many thanks for the info.. I needed this to progress :D
@this-is-gamedev
@this-is-gamedev 18 дней назад
Awesome! Good to hear!
@Ranger8744
@Ranger8744 Месяц назад
Uhhh, He called me dedicated... I'm touched🥺!
@MattMurphy-e2g
@MattMurphy-e2g 6 месяцев назад
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 5 месяцев назад
It's more ML than AI, not all ML is AI
@technicalm.t.b5251
@technicalm.t.b5251 6 месяцев назад
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 <a href="#" class="seekto" data-time="706">11:46</a> ?
@Linguin_
@Linguin_ 6 месяцев назад
Does it still work? I can only bak the Mesh in "Navigation Obsolete "
@this-is-gamedev
@this-is-gamedev 6 месяцев назад
Yes, just the AI navigation is now a unity package. But its API is the same.
@Linguin_
@Linguin_ 6 месяцев назад
Ok thx
@squirrelzar
@squirrelzar 11 месяцев назад
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 11 месяцев назад
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 11 месяцев назад
@@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 11 месяцев назад
@@squirrelzarNo worries. I am listening to all feedback and ideas. :D
@thebestcelep6358
@thebestcelep6358 Год назад
High quality!
@OrdeBaruMilenial
@OrdeBaruMilenial 6 месяцев назад
Rockstar must hire this guys.. for the next evolve game think..
@Elliooo123
@Elliooo123 24 дня назад
How do I make it so the enemy can kill the player?
@this-is-gamedev
@this-is-gamedev 24 дня назад
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 23 дня назад
@@this-is-gamedev thanks!
@ruisilva59
@ruisilva59 9 месяцев назад
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 <a href="#" class="seekto" data-time="1519">25:19</a> please i need help
@this-is-gamedev
@this-is-gamedev 9 месяцев назад
EnemyBrain_Smart has the state machine inside. You can’t use a transition -> you have to ->
@강성원-i5o
@강성원-i5o 6 месяцев назад
프로젝트에서 적을 구현하는 것에 큰 도움이 됐습니다. 감사합니다.
@Abdullahkhan-lk5zl
@Abdullahkhan-lk5zl 9 месяцев назад
Hey man, GREAT Video. Where can i get your code.
@ahmaddalao
@ahmaddalao 9 месяцев назад
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 9 месяцев назад
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 Месяц назад
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 Месяц назад
Awesome! There is a lot to learn in this subject! Happy if this hells you start!
@am-apps-games
@am-apps-games Год назад
Very well done! Thank you
@this-is-gamedev
@this-is-gamedev Год назад
Thanks! I am glad you like it!
@MotabhaiOp-u8g
@MotabhaiOp-u8g 6 месяцев назад
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 5 месяцев назад
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
@LagowiecDev
@LagowiecDev Год назад
Thanks for making tutorial for noob like me! :D
@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.
@cosmotect
@cosmotect 6 месяцев назад
Smarter every day reference?)
@this-is-gamedev
@this-is-gamedev 6 месяцев назад
If that’s the case, not done on purpose 😌
@iliagusarov8662
@iliagusarov8662 10 месяцев назад
What should I do, if I have a big open world? Or I can do the same stuff?
@this-is-gamedev
@this-is-gamedev 10 месяцев назад
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
@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.
@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 Год назад
​@@this-is-gamedev Thank you so much..❤ Im from Iran, and there is no one to ask him, and I get lost
@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
@President_PunchLines
@President_PunchLines 6 месяцев назад
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 6 месяцев назад
Thanks! Mmm, this might be some pivot issue
@President_PunchLines
@President_PunchLines 6 месяцев назад
@@this-is-gamedevthanks man I already solved it it was a code issue
@DionteHelm
@DionteHelm 11 месяцев назад
This was really informative. Thanks man.
@this-is-gamedev
@this-is-gamedev 11 месяцев назад
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
@muhammadzubairirshad6724
@muhammadzubairirshad6724 7 месяцев назад
Just Amazing
@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
@санитарпсихбольницы
@санитарпсихбольницы 11 месяцев назад
<a href="#" class="seekto" data-time="723">12:03</a> - genius mem
@venkatswaraj3054
@venkatswaraj3054 Год назад
Thank you. This is what I am looking for.
@this-is-gamedev
@this-is-gamedev Год назад
Nice! Happy it’s helpful :)
@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 :)
@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
@sklintergames6662
@sklintergames6662 10 месяцев назад
Great tutorial , thanks 🎉
@this-is-gamedev
@this-is-gamedev 10 месяцев назад
Thanks! 🙏
@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
@androvictrayo-dy7eh
@androvictrayo-dy7eh Год назад
This is a fantastic tutorial
@this-is-gamedev
@this-is-gamedev Год назад
Thanks! Happy you like it!
@afrodidcraft
@afrodidcraft Год назад
merci frerooo
@this-is-gamedev
@this-is-gamedev Год назад
De rien 😉
Далее
Unity Next Gen UNVEILED! (and news from Unite)
28:09
Просмотров 30 тыс.
The Trick I Used to Make Combat Fun! | Devlog
8:12
Просмотров 1,6 млн
ПОЮ ВЖИВУЮ🎙
3:19:12
Просмотров 880 тыс.
Ranking ALL Design Patterns for Games under 30min
25:51
Creating SMART enemies from scratch! | Devlog
5:40
Просмотров 331 тыс.
20 Advanced Coding Tips For Big Unity Projects
22:23
Просмотров 186 тыс.
3D ENEMY AI in UNITY - (E01): STATE MACHINE BEHAVIORS
17:24
Triton Conference 2024: Morning Session
1:37:43