Enemy AI Following/Chasing - #25 Creating A First Person Shooter (FPS) With Unreal Engine 4

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] good afternoon ladies and gentlemen your boy virtus here and welcome back to the Unreal Engine 4 FPS series in today's video we are gonna be showing you how you can make your a I follow your character so at the moment our AI is just pretty much you're standing there in place we can shoot it we can kill it and all of that good stuff so what I want to do in today's video is just get it to follow your character so what I wouldn't need to do then to turn this into an actual a I where we can have it follow us we need to do a few things first things first we need to set up some code so that we can tell it to follow the character we also need to set up a navigational mesh this is essentially something that is going to be inside of your level and it tells the characters when I say the character I mean the AI where it can and cannot go so let me show you how to do that first otherwise everything in terms of script that we do is simply not going to work what you want to do is go over to volumes and then you want to find your nav mesh bounce volume if you click and drag and drop it into your scene here you can see we get this little box this is essentially the navigational space for your character now this is automatically going to grab information from collision within your scene so it's going to tell the characters that they cannot go within you know save the areas with collision so let me show you what I mean by that if I make this box a little bit bigger just like this and then press P to turn on my pathfinding you can see I've got my green space which is the bits that they can go into however if I go and drag it over here just to the left a little bit you can see it's gonna go and just miss a little bit around the collision and it's automatically going to generate those bounce volumes for us so with this done what I'm gonna do then is essentially just make this nice and big on all of the axes both X and then Y just like this and then I'm just gonna drag it over make sure it fits in perfectly and that's all good if you want to do this a bit quicker just go into the details panel and then from here you can set all of from the scale on here and you can see now if you notice it's automatically generated that collision for the top of your objects and all of that good stuff now if you don't want it to be able to go up to this height all you would essentially do is essentially just scale this down so that it doesn't cover the top layer so let me show you exactly what I'm talking about so you can see I've got my volume here essentially what I'm gonna be doing is just moving this below the level so that it only covers the ground piece of the floor now it's gonna take a little bit of adjustment to get this right but once you do get it it's gonna stop them moving up to those higher locations anyway with that done it's time to actually get our characters moving and following the character now if you remember in our previous videos we set up this simple AI character this is just a blueprint so what I'm gonna do is open this up real quick and we're going to start putting some scripts and a few other components into this so give it a couple of seconds to load up and then we can do that now if we go into the viewport there's one thing that we need before we can do anything related to AI so that is at the component for porn sensing so if you go to add component in the top left hand corner go to porn sensing and then just add this into your scene what this allows us to do is pretty much just generate a event for when the player actually sees a porn a porn essentially being a character blueprint one that you're going to be controlling yourself and then from that we can tell it to do all kinds of actions for you know moving the AI and all of that good stuff so with this porn sensing if you compile it's going to pretty much generate the little volume so you can see it inside of your viewport so if you can't see it when you have porn selecting you know selected just go ahead and hit compile and then you're gonna see you have this green radius this is essentially the angle of view of your pond sensing so what you need to do because it's really wide at the moment a little bit unrealistic you need to turn that down and the way that you're gonna turn this down is just by reducing the sight radius so this is gonna change sort of the length whereas we've got another control over here for afro vision and if you turn that down you can control sort of the the width of your you know your peripheral vision now for me I like to have a peripheral vision of maybe about thirty five just like this and I think also I like having it quite long as well so they can see it from a distance so I want to leave it pretty much just like this now when you do get your eye in here what you might want to do is just play around with this pawn sensing volume with your playtesting to want them to be able to see you from a distance doing it to be wide you want it to be closer it's entirely up to you but that's something you can play around with once you have all of this set up so with this section done what I'm going to do then is essentially move on and create the events for when this character sees the pawn so you can see in the bottom right here in the details panel with the porn sentencing selected I have got on see porn if I press plus next to this I can create an event with it now don't worry about the rest on here noise or on component and all that stuff the only one we're working with to do it is on C porn press plus and that is going to create you a blueprint node for this event now the porn is going to be the one that we are controlling the one that we want it to you know the one that it sees if you hook up the third person character and it sees anything else it's not going to do anything so the porn that we're going to be working with is going to be cast to third person character and this is just essentially the character that the player is going to be controlling and now what I've done this what I can do is I've got this little event and I'm just going to test this to make sure that our AI can see it so I'm going to print a string after this and whenever it does see the porn so I'm going to tell it to say hello so if I hit compile close this and then press play and then if I walk in front of these you can see it says hello because you can see us so we know that's all working what we're going to do then is open up this blueprint once again we're going to delete the print string and we are going to use a node called AI move to and then with this we can pretty much tell it to go to Eva right a destination or we can tell it to go to a target actor so what we're gonna do is tell it to move the porn and also a target access to the porn is essentially itself so what I want to do is drag that out make a reference to itself so type in itself and then you'll see it says here get a reference to self and then for destination you could do this either two ways you could essentially set the destination to enact a location a preset destination in your level but for me what I like doing is to twerking up third person character to your target actor and it's going to move it to that location which is quite nice so if I go ahead and hit compile now press play and then if I run in front of these you're gonna see they start running towards me and it's the same for both of these and it's all good and that's pretty much just the basics of our AI they will pretty much follow us until it gets to us and we can still shoot them down just like this and yeah that's pretty much the basics of our AI we've still a little bit more work to do with these and that's going to be getting our AI to shoot we're going to get into Rome when they're not seeing anything and all of that good stuff but anyway guys that's pretty much everything for today's video once again guys thanks for watching stay awesome keep creating you boy virtus signing out this series was made possible by you guys supporting your a channel if you want to help create other series like this and check out my patreon page and the link in the description [Music]
Info
Channel: DevSquad
Views: 49,371
Rating: undefined out of 5
Keywords: Unreal Engine 4, UE4, FPS, FPS Tutorial, FPS Game, First Person, First Person Shooter, Unreal Engine 4 FPS Tutorial, unreal engine, VirtusEdu, Virtus Learning Hub, Game Dev, Game Design, Shooter Tutorial, How to make a FPS game, Beginner, Blueprints, Unreal Engine Tutorial, FPS Tutorial Series, Tutorial Series, Player, Weapon, Gun, Weapon UE4, Damage, AI, Artificial Intelligence, Bullet, Projectile, Follow, Chase, Navmesh, Navigation
Id: 87lkYjAgYoc
Channel Id: undefined
Length: 8min 15sec (495 seconds)
Published: Mon Aug 28 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.