AI Random Roam | Basic Roaming - Unreal Engine 5 Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys and welcome back to another overvention 5 tutorial in today's video we're going to be going over is setting up random rome for our ai so it's just going to randomly walk about the level and just do its own business so if we hit play you can see what this is going to do so you can see we have an ai in the level that's just randomly walking about as you can see here and we can customize this to move longer distances shorter distances and in different areas as well and we can obviously have as many different ai in here in the level as we want so if i were to just drag in some more we should be able to see them just walking about perfectly like so so this is what we're going over and creating today so without further ado let me delete this code and i'll show you how i've done it so the first thing you want to do is you obviously want to actually create your ai so let's press ctrl space to go into our content browser and what i'm going to do is go into my third person folder blueprints and select and copy so hit control c my third person character blueprint i'm going to go back to the folder where i want my ai and hit control v to paste that character blueprint there i'll hit f2 to rename it and just call it ai like so opening it up straight away and then i'm going to delete all the code and components that i don't need for example the camera and all that stuff and i'm also just going to change the mesh over to be the male mannequin instead of the female one just to make it slightly different so we'll compile and save that there and the reason why i duplicated the character blueprint is just because it has all of this good stuff here already set up for us obviously you can get that as well by just creating a new character blueprint but this is just an easier and quicker way of doing it so to actually do the random rom code what we're going to do is right click anywhere on the event graph and add a custom event naming this random rom or whatever you want to call it out of this we're going to get ai move to the kind of white box next to it there and the pawn is going to be get a reference to self as the pawn is just the ai which it wants to move so we obviously want to move this current ai that we are in so we're going to get reference to self out of destination so where we want the ai to move to what we're going to do is get random reachable point in radius so it's just going to get a random area that it can actually reach within a certain area which we choose so the radius i'm going to put at 2500 anywhere between 1000 and 3000 is good for a small area for example the one which i have here by default and the origin you can either put as the center of the map or what i like to do is just get actor location so where the ai currently is the difference between getting the ai location and the map location is in the map that will be a static location so it will only be in a certain area but if it's the ai location then it will constantly be changing so they can explore the entire map in the area which we define ais to actually be able to move in and that is pretty much it although what we're going to do is on success call function random rom again so once they get to that location they're going to continue moving now what you can do is you can put a delay after the on success and before random roam so it just waits a little bit before moving again but i like to keep it like this because it just looks nice and fluid so we'll compile and save that and that is all the code done for us all we need to do we'll close this and the final step in the project is just to actually define the area that the ai's can move in so this also just allows them to actually move so what we're going to do is go up to the add to project up in the top left here go down to volumes and get the top one of nav mesh balance volume and again this just means the ai can actually move in our level so what we want to do is just place this in the middle of our level somewhere and then just expand this to cover the area and the size which we want the ais to be able to move in again also making sure you go vertically as well so they can go both up and down too and just to test to see where this covers we can press p and anywhere that is green means the ai can go there so this is perfect for me if it's red that means they can't move there and if there's nothing there so it's not green or red that also means they can't go there so you want to make sure you move it about until it's perfect for you so if i just drag some ai in the level we should see this working perfectly of them all just moving about random roaming minding their own business hit play like so and you'll notice they're not actually moving so let's have a look at why that is and i would and i do actually know it's because i forgot to actually call this random rom code to begin with so what we're going to do is hold down p and left click to get event begin play out of this call random rom and that's all we need to do we just forgot to actually start off this function so we'll compile save close this and hit play and now this should be working perfectly as you can see here now obviously they're all running about going at max speed same as i am so you can obviously change their max speed the same way you would with your character obviously that's just extra customization which you can choose to do but i think that'll be it for this video is we've done everything we wanted to do what we did was we created an ai which will randomly roam and just walk about the level randomly wherever it chooses to go as you can see perfectly here like so so thanks so much for watching this video i hope you enjoyed it and i hope you found it helpful and if you did make sure to like subscribe down below so thanks so much for watching and i'll see in the next one [Music]
Info
Channel: Matt Aspland
Views: 33,320
Rating: undefined out of 5
Keywords: ue4, unreal engine 4, unreal engine, tutorial, ue4 tutorial, unreal engine 4 tutorial, how to make a game, how to, blender, unity, games design, ue5, unreal engine 5, unreal engine 5 tutorial, ue5 tutorial, ai, basic, smart, move, moving, movement, roam, roaming, ai move to, to, duration, random, randomly, range, chase, npc, walk, walking, idle, run, animation, create, game, better, enemy, damage, attack, evil, team, opposing, opponent, opposite, nav, mesh, bounds, volume, navigation, ue5 random roam, ue5 ai
Id: Mi7r0LqUmOE
Channel Id: undefined
Length: 5min 33sec (333 seconds)
Published: Sat Jun 25 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.