Тёмный

Managing enemy state using State Machines in Unity [AI #03] 

TheKiwiCoder
Подписаться 18 тыс.
Просмотров 32 тыс.
50% 1

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

 

2 окт 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 78   
@robertbradford8210
@robertbradford8210 2 года назад
One tiny thing as well. I'm not sure if I missed something here, I have been following along. but the locomotion script seems to be wildly different from the last vid. Maybe start with explaining changes you have made previously or run with the old (even if it is worse) script just because it can lead to some confusion
@ultmatepotato
@ultmatepotato 2 года назад
yea he did and no you did not miss anything.
@drr1867
@drr1867 2 года назад
Same trap most fall into - changing code between next tutorial. Totally f'd up my working code.
@CellarPhantom
@CellarPhantom Год назад
If anyone is wondering, it still works with the old code.
@diduward9360
@diduward9360 Год назад
​@@CellarPhantom thx for letting me know
@consultingprestig2096
@consultingprestig2096 Год назад
I confirm what you say! They piss off these guys who change things without talking about it! In programming, there are a lot of guys like that! they suck!
@kashyap0072
@kashyap0072 3 года назад
Thanks man. I was waiting.........
@NorthstriderGaming
@NorthstriderGaming 2 года назад
Thanks for your approach on this one but I think I'd do a few things a little bit different: - I'd scrap the AIAgent entirely. It adds nothing to this whole construct that cant be moved over into the StateMachine. The machine as component would be quicker to use and offers more straightforward setup possibilities like directly defining the available and initial state. - I'd build a AIState factory to create instances of states by enum value which can be pre-defined in a public array. No hardcoding of instances. But otherwise I'm fine with your other parts. Especially the interface part is neat since I'd just gone with a class full of virtual methods to override instead.
@TheKiwiCoder
@TheKiwiCoder Год назад
- The AiAgent was an intermediate component that I built on for the rest of the series (basically a component cache). But I do agree the statemachine could have been a component. I can't remember exactly why I chose this approach at the time but I'm sure I had a reason. - The idea was to keep the enum separate from states so you could map different types of 'attack' states for different enemy types to the same enum. But the other states could still enter a generic 'Attack' state regardless.
@HackDaMainframe
@HackDaMainframe 3 года назад
You’re tutorials are so good! Just curious (no rush or pressure) but do you ever plan on doing a first person tutorial?
@TheKiwiCoder
@TheKiwiCoder 3 года назад
Thanks! FPS.. it will be some time but yeah I’d love to cover it.
@HackDaMainframe
@HackDaMainframe 3 года назад
@@TheKiwiCoder good to hear man! I wish you continued success and thank you so much for these tutorials.
@Democracyphobia
@Democracyphobia 3 года назад
thanks a ton for these tutorials . just subbed .
@marveII0us
@marveII0us 3 года назад
Great content, very nicely taught and concise. Thanks a lot :) Definitely a sub from me!
@bartkaron1935
@bartkaron1935 3 года назад
Hello! Next episode! :) Thanks!
@subhendumukherjee4722
@subhendumukherjee4722 2 года назад
Great Tutorial of State Machine.
@itsalwaysoniontime
@itsalwaysoniontime 9 месяцев назад
I'm at 6:46 in the video and keep getting this error when I save the script: 'AiChaseState' is missing the class attribute 'ExtensionOfNativeClass'! followed by this warning: GameObject (named 'Enemy1') references runtime script in scene file. Fixing! Help would be appreciated.
@gorrillaconvention
@gorrillaconvention 3 года назад
Incredible. I can follow and understand...somewhat. How people know all of this I don't think I'll ever understand.
@otaku_mat
@otaku_mat Месяц назад
Same
@fletchergunderson5283
@fletchergunderson5283 11 месяцев назад
I know this is a bit old, but why are you putting "?" in your calls? For example GetTate(currentState)?.Enter(agent)
@TheKiwiCoder
@TheKiwiCoder 11 месяцев назад
It prevents a null reference exception if the thing in the left returns null, then the call to the right of the ? Will get ignored
@unjavibu
@unjavibu 2 года назад
On min 2:54 the lane int index = (int)state.GetId(); it tolds me i can not convert AiState in to an int Any help pls?
@jasonisaderro
@jasonisaderro 2 года назад
The GetId function should have a return type of AiStateId not AiState
@StressedProgrammer
@StressedProgrammer Год назад
whats the meaning of this line: GetState(currentState)?.Update(agent);
@erikhokis6292
@erikhokis6292 3 года назад
Thank you for good video, any advice how i implement public array of waypoints into it? Scriptable objects unsupport Transforms or GameObjects .
@erikhokis6292
@erikhokis6292 3 года назад
If anyone needs it i attach waypoints transform array into Aiagent and into scriptable object created bool, if aiagent go for random waypoint or cycling it from start.
@acidrain9924
@acidrain9924 3 года назад
Is there a way to offset the npcs? I mean they follow the main player in a line
@TheKiwiCoder
@TheKiwiCoder 3 года назад
If you add a navmesh obstacle to the agents and they should try to avoid each other.
@mishaaskar
@mishaaskar 9 месяцев назад
A bit complex with all the State stuff but great tutorial helped me alot :)
@RayHorn5128088056
@RayHorn5128088056 2 года назад
Scriptable Object work so much better.
@a_lister242gaming7
@a_lister242gaming7 Год назад
Hello, I'm using this playlist for a college project. I keep getting stuck on the AiChasePlayer script. I getting a NullReferenceException error with the code. I don't see the issue with m ycide and I've been following along pretty well with the video. Is there any way you or anyone can help?
@consultingprestig2096
@consultingprestig2096 Год назад
I think I had the same error. I had put an Update() function in private when it had to be put in public. Try to see if you have not put certain functions in private and also see if you have correctly assigned the components " GetComponent() ". If you want, you can send me the error line so that I can help you. Good luck !
@Injabsful
@Injabsful Год назад
awesome stuff i was looking for something like this ,, sweet !
@GigaNigga1111
@GigaNigga1111 7 месяцев назад
At the end I get an error with dotProduct "Operator '>' can not be applied to Operands of type 'float'". Can you please explain how to fix that? 17:17
@qasimahamad5075
@qasimahamad5075 2 года назад
Sweet, Aannnd yeh COOL!
@BORNIS
@BORNIS 2 года назад
Cool!
@УральскийГном
@УральскийГном Год назад
It's very cool lesson, but I quess you must understand more details, bro
@gamdevgamdevpropro2781
@gamdevgamdevpropro2781 Год назад
good one.
@svet7715
@svet7715 2 года назад
"currentState" doesnt exit error thanks kiwi
@TheKiwiCoder
@TheKiwiCoder 2 года назад
Welcome 🤗
@syedhuzaifaali5322
@syedhuzaifaali5322 3 года назад
Awesome tutorials. But this AI stuff is a bit difficult to understand :P
@TheKiwiCoder
@TheKiwiCoder 3 года назад
Apologies, I hope it wasn’t my explanation :)
@robertbradford8210
@robertbradford8210 2 года назад
So everything goes well until I get to 6:35 and then I can't do the alt enter bit? I have poured over the script I may have missed something in my frustration but it looks identical but it throws back the error error CS0103: The name 'AiState' does not exist in the current context
@robertbradford8210
@robertbradford8210 2 года назад
Any help much appreciated
@franklambeth1148
@franklambeth1148 Год назад
I got the same error every frame I ran the game but the problem was that you need to go to your player game object in the hierarchy and use the drop down for tag and select it as player
@robertbradford8210
@robertbradford8210 Год назад
@@franklambeth1148 Thanks!
@rustyryan4473
@rustyryan4473 3 года назад
thanks for the shoutout, Kiwi :P
@TheKiwiCoder
@TheKiwiCoder 3 года назад
No problem Ryan! Thank you for your generous support :)
@jasonb202020
@jasonb202020 3 года назад
The simplest and the best finite state machine tutorial on the web. Awesome.
@FelineRaptor-gv4te
@FelineRaptor-gv4te 2 года назад
please help i'm getting this error- Assets\MyScripts\AiChasePlayerState.cs(5,35): error CS0738: 'AiChasePlayerState' does not implement interface member 'AiState.GetId()'. 'AiChasePlayerState.GetId()' cannot implement 'AiState.GetId()' because it does not have the matching return type of 'AiStateId'.
@karimdaman8587
@karimdaman8587 3 года назад
kiwicoder at it again!!!
@TheKiwiCoder
@TheKiwiCoder 3 года назад
Once you pop you can’t stop 😂
@毛豆豆-r8p
@毛豆豆-r8p 3 года назад
How do you determine a target point for the AI to reach :D!
@TheKiwiCoder
@TheKiwiCoder 3 года назад
First decide what the ai wants to do and that will determine where it wants go.
@毛豆豆-r8p
@毛豆豆-r8p 3 года назад
@@TheKiwiCoder sry,what I'm trying to say is,i have a target Point, I'd like to know this point whether On the NavMesh.
@毛豆豆-r8p
@毛豆豆-r8p 3 года назад
@@TheKiwiCoder Because I want to implement a random roaming feature
@TheKiwiCoder
@TheKiwiCoder 3 года назад
@@毛豆豆-r8p use this: docs.unity3d.com/ScriptReference/AI.NavMesh.SamplePosition.html
@毛豆豆-r8p
@毛豆豆-r8p 3 года назад
@@TheKiwiCoder thanks
@Alex_online
@Alex_online 3 года назад
Love the tutorial, can't wait to try it out. Would you ever consider a follow up tutorial for implementing this state machine with MLAPI?
@TheKiwiCoder
@TheKiwiCoder 3 года назад
Yep! I'm keen to get involved with MLAPI very soon..
@BreakingMaster1
@BreakingMaster1 3 года назад
Amazing video! Just a question, how do I implement different types of enemies using this state machine structure? Do I just make a new State script for each type of enemy deriving from the "AiState" and register the correct StateMachine on the Start function?
@TheKiwiCoder
@TheKiwiCoder 3 года назад
Yep, so you’d need a script per enemy type to register the correct states. Some states could be shared across enemy types if it makes sense.
@a.belmont1500
@a.belmont1500 2 года назад
@@TheKiwiCoder Hello. I have the same question, but I don't think I fully understood your answer. Can you elaborate a bit more about how to asign each AiAgent diferent states please? Thanks :)
@nitrobuilder1014
@nitrobuilder1014 2 года назад
I also have a question of how you would reuse states when they are looking for a specific state to exit to
@thewightone7441
@thewightone7441 3 года назад
Love this video, perfect for a project of my own with a little tweaking, but in the future do you think you could explain more in-depth as to why you do things the way you do? In this video, for example, I'm not sure why we need to register states or have an array of enums that just lists each enum. why not just function off of the enum itself?
@TheKiwiCoder
@TheKiwiCoder 3 года назад
Hey yes I will try! The reason for the register state is it allocates the state ahead of time. So switching states doesn’t trigger an allocation and thus no garbage to be collected.
@thewightone7441
@thewightone7441 3 года назад
​@@TheKiwiCoder What an absolute legend. Keep it up man, your vids are awesome.
@bartkaron1935
@bartkaron1935 3 года назад
The episode is great, thanks for sharing. Will you cover other state like: - Stage of shooting + switching weapons - Stage of hiding behind a cover (probably tricky one) - Stage of idle till Player do some kind of behavior (shoot to Agent), then Agent will run away or will attack a player. - Stage of patrolling (walking from point A to point B, possibility to have more points (this sounds pretty easy) Also how about Agent's FOV, so when player is in Agent frustum it will change his stage. maybe this will inspire you with some new stuff for your next tutorial episode if you do not have any! :)
@TheKiwiCoder
@TheKiwiCoder 3 года назад
Yep all this stuff is planned and coming, stay tuned!
@bartkaron1935
@bartkaron1935 3 года назад
@@TheKiwiCoder sounds promising!
@adeveloper7184
@adeveloper7184 3 года назад
@@TheKiwiCoder If all the above said things are coming sooner then it would really help my existing project
@bartkaron1935
@bartkaron1935 3 года назад
@@trod146 mate, dont be toxic here. My profession is not related to the game. And I assure you are wrong. I am happy to see more stages because I would like to learn how to make it properly. TheKiwiCoder said he worked in a game company so he knows so many useful and handy stuff and correct way of using them. Please be cool to others, we dont need any hate on his channel.
@atomialep
@atomialep 2 года назад
Amazing video thank you so much, love your humour. Such a great teacher!
@hatakeroze1969
@hatakeroze1969 3 года назад
When i added the aiagent scripts and dragged everything from what you mentioned in the video, my ai doesn't move and when the ai's health dropped to 0, the ai ragdoll seems to be negated
@jamiljawhar4711
@jamiljawhar4711 3 года назад
Just to know, did you bake navMesh area?
@trexarain794
@trexarain794 3 года назад
Kiwi please tell how to add mobile input
@vikramaditya1364
@vikramaditya1364 3 года назад
Bro I need recoil system for 2d make a tutorial for it. Please..........
Далее
БАГ ЕЩЕ РАБОТАЕТ?
00:26
Просмотров 111 тыс.
МАЛОЙ ГАИШНИК
00:35
Просмотров 460 тыс.
ENEMY AI - Making an RPG in Unity (E10)
9:25
Просмотров 536 тыс.
How to code SMARTER A.I. enemies | Unity Tutorial
32:49
Unity line of sight checking using sensors [AI #08]
19:24
How to Program in Unity: State Machines Explained
18:56
Negative Time is Real, Physicists Confirm. Kind Of.
6:59
How to use Unity NavMesh Pathfinding! (Unity Tutorial)
15:25
REALISTIC Foot Placement Using IK in Unity
30:09
Просмотров 129 тыс.
Creating your first animated AI Character! [AI #01]
22:11