New AI Navigation in Unity

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this is a new video taking a look at the new AI navigation system that is available in unity first of all you will have to go into the window package manager and actually install the AI navigation okay it doesn't come installed by default anymore so once you've installed it you may very well see this kind of overlay whereby you can actually switch the nav mesh surface on or off I haven't baked one yet so you won't see it but you will notice this you can right click on it and choose to either collapse it down or expand it or even hide it okay if you want to get it back in the scene view you've got little dots you've got your overlay menus and you can switch it on or off here okay so I'll leave it on for now um to create an actual NAB mesh surface all you need to do is go to game object the new Ai and create a nav mesh surface you can choose which agent type this is going to affect okay the moment I've only got humanoid but I'm going to set up two different agent types for two different characters um and then simply you can bake you no longer need to make all of your objects static in order to bake okay we'll just automatically bake and then as soon as I switch on my nav mesh you can see where that is going now one of the big things that you will notice straight away is that it is actually cutting out um spaces for the characters themselves and if those characters start to move those spaces kind of stay in place so what you need to do there is basically switch off any characters that are Dynamic that are going to move and then go back to nav mesh surface and bake that way it will not cut them out and then they will move perfectly fine if for example you want to let's say this column not to be included for some reason you can then add a nav mesh modifier and the modifier could remove the object okay under the nav mesh surface if I then bake you'll notice that that gets removed okay but I don't want to do that so I'll just do control z a few times and let me put the column I've removed that nav mesh surface and bake and at any point you can switch off your nut mesh so that you don't see it in your scene as long as you've got gizmos switched on you can see it and I want to give this larger player a different nav mesh agent so to do this you would go to window Ai and make sure you're clicking on the new navigation not the old obsolete one and from here you can actually Define a whole number of different agent types so if I click plus you can rename this let's call it enemy 2. this one has a radius of one okay so it's a little bit wider that means that this particular character probably won't go through that door we'll have to walk all the way around to actually get to the player this one can probably go through that little doorway okay you can change the values on any of these types you've also got different walkable areas as well you can put in as many of these as you like these ones are the default walkable not walkable and jump okay so uh for enemy one uh I probably want to click add component given that nav mesh agent okay and obviously I can Define the speed everything stays the same as it used to be um and for enemy 2 I also want to give it a navmesh agent agent type is enemy 2 on this one uh on enemy one it is choosing to use humanoid okay at any point you can change that over um everything is good so what I need to do now is basically write a script which I have done previously all right using the unity engine AI now mesh agent make sure it's got the player it will automatically get the nav mesh agent and set the destination to the player position so now it's just a case of placing this on there and dragging the player object into the slot quite easy I've got that my nub mesh surface uh agent type is humanoid uh so what they need to do that I need to add a component another nav mesh surface and make sure this is set to enemy 2. okay so and then basically bake again all right so I bake a second time and what I will see this time for this uh second one if I switch on my surfaces um and switch off my first one is that this will not allow this second character to actually go through that doorway notice that there's a big gap there but for my first one this character can walk through there all right so you need different bakes for different character types switch them both on so that now when I play great they're both moving notice that the bigger one has to go all the way around okay they both get to the player now if I go back into my scene and let's say take the player I'm just going to move my player down here notice this one has to go all the way around the little one can go through the door if I go back up here notice they're chasing my player um let's come back down here excellent all right so both characters are walking a different way you can also add a navmesh modifier directly from the game object Ai and then that mesh modifier volume okay um so let's say that I put a safe area for my player up here I'm going to make it just a little bit bigger um and I will make this one not walkable and it will affect all agents or if you have multiple agents you can actually only affect certain ones by selecting them and then once I've done that if I go back to my nav mesh surface switch this on and make sure I switch my characters off there um I can then rebake and notice that that particular area now gets cut out of the nav mesh so if I now switch my characters back on and in the game scene I begin to play okay they can find my character no problem but then as soon as my character kind of walks into this not walkable area notice they can't reach me now because that is a not walkable area okay but as soon as I come back into this Blue Area they can now chase me around and all of these by the way are available in the package manager AI navigation and in the samples section you can download import those and it actually gives you a few scenes that show you how to use this AI navigation system including using um the navmesh link which is used for allowing AI characters to jump across gaps okay so hopefully that helps you to get started with AI navigation if you're using an older project that has the older AI system it should still work you can upgrade it but if you want to add your own AI navigation system and these newer versions of unity you will need to use this new system
Info
Channel: Creative Media Tutorials
Views: 59,301
Rating: undefined out of 5
Keywords: AI, Navigation, Unity, Unity 2023, AI Navigation, Package manager, NavmeshAgent, Computer controlled, NPC, npc, Guide, tutorial, Unity error
Id: u2EQtrdgfNs
Channel Id: undefined
Length: 8min 22sec (502 seconds)
Published: Mon Jun 19 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.