‫Hello and welcome.
‫In this lecture, we're going to be getting at eye to followers and navigate around the world, avoiding
‫obstacles and just generally being a little bit of an annoying nuisance.
‫Let's dive in and see how this is possible.
‫So the next most obvious, obvious piece of the puzzle that we need to sort out here is getting our
‫eye to move towards us.
‫It's no good them just standing there.
‫They also need to move and then they'll need to shoot.
‫First of all, let's figure out how we can do movement.
‫Now, when you're moving with eye needs to know about obstacles, it needs to do something called pathfinding
‫because say, I'm hiding down in this corridor here and it wants to get to me.
‫It needs to know that it can't just move through the wall.
‫It's going to need to plan its route to come around the obstacles and come towards me.
‫Now, the way this typically works in games in general and specifically here in Unreal is that we generate
‫a mesh which tells us where is walkable within a level and then using various algorithms, one of which
‫is called a star path finding.
‫You can navigate on this mesh and create a route plan and the AI then uses this route plan to move along.
‫So that's the kind of outline of the process.
‫Fortunately, a lot of that is done for us.
‫We don't have to code this from scratch.
‫So what we need to do is, first of all, be able to see the nav mesh.
‫And at the moment we can't see enough mesh partially because there isn't one.
‫So what we need to do is look in our placed actors window here, or so we go to window and look for
‫placed place actors.
‫We need to search for a nav mesh and we're looking for the nav mesh bounds volume.
‫Now this creates a volume, a kind of box, and everything within that box is going to be checked for
‫how navigable it is, basically, whether it's flat or whether it's not too steep.
‫Basically where there's a wall, you can't go through walls, you can't walk over walls because they're
‫too steep.
‫So if we drag in a nav mesh bounds volume and just bring it here and just put it slightly through the
‫floor so that this allows the floor to be part of that navigation calculation, then what we've got
‫to do is enable the visibility of NAV meshes.
‫You can do this by clicking on the show button in the top left of your viewport and then clicking on
‫navigation or using the shortcut.
‫P So I'm going to use the shortcut.
‫P And selecting well, you don't even have to select the bounds volume.
‫You can instantly see this green mesh has appeared within the bounds volume which is telling us this
‫is a walkable area.
‫So if we had our enemy within this area and his target was also within the area, then it could find
‫a path along this mesh.
‫Now let's have a look at what happens if we move this to where there's an obstacle.
‫You can see that the mesh kind of cuts out around this obstacle.
‫So what we actually want to do is have this volume encompass the whole of our level and you could choose
‫not to or just do it in certain segments, but the easiest way is just to increase the bounds of this
‫volume, which you can do.
‫If you go over to the details pane on the right, there's the brush settings and you can change the
‫size of the brush like so you can see we can make it larger, we can make it wider and it goes red when
‫it's being recalculated.
‫You can see it's doing that building nav mesh and the larger it's going to be, the harder it is going
‫to be to build a nav mesh longer it's going to take.
‫But you can see that this is working.
‫It's cutting out the corridors.
‫It's cutting out the obstacles that we can't walk around.
‫The second part of this puzzle is having our eye able to do its rooting algorithms on this mesh.
‫Now, let's go ahead and open the BP shooter eye control, because I want to show you something that
‫is in here.
‫I'm going to open up the full blueprint editor here and have a look here.
‫There is a component called the path following component.
‫That component is responsible for finding an F mesh and then basically allowing us to create paths and
‫follow them and move along them automatically.
‫So we don't have to build any of that functionality in.
‫All we have to do is use a function that's available on our AI controller.
‫If you go and search for the AI controller H and look for the move to function, then let's do move
‫to with an open brackets.
‫Then there's a couple of options here.
‫We've got a one takes a move to request.
‫There are some other options here too, but they actually go by a different name.
‫Now, in later versions of Unreal, we've got move to actor and we've got move to location, which have
‫the same distinction as our setting focus.
‫You can set focus to something that's moving like an actor, or you can set focus to a specific destination
‫such as a waypoint in your patrol route, for example, might be a move to location.
‫So I'd like you to have a go at attempting a move to as your challenge.
‫So get a nav mesh in your scene, make it cover as much of the scene as you need to for you to be able
‫to move around and have the.
‫I follow you in all locations and then call that move to either move to act or move to a location.
‫You decide which inn begin play to get the AI chasing us.
‫So pause the video and have a go.
‫Okay.
‫Welcome back.
‫Let's give this a shot.
‫So first things first.
‫We're going to have I'm going to be using a move to actor and we're going to have to set the goal actor.
‫So let's go over to our shooter I controller CP and in there begin play we can do move to actor and
‫we've got an actor already the player -- which we've got from the last lecture and let's just have
‫a look.
‫Are there any other useful properties here?
‫We've got an acceptance radius.
‫At the moment it has no acceptance radius.
‫Basically it gets as close as it possibly can.
‫I think that might be a little bit encroaching.
‫I'm going to give it an acceptance radius of two meters, so it will try to get within two meters of
‫us.
‫So let's go ahead and build that.
‫And once that's complete, go over into the engine.
‫And let's have a look.
‫I'm going to not expand the bounce volume here just to give you a taste of why we need the bounce volume
‫in the first place.
‫So let's start off with an alt p.
‫And here we are.
‫We're on the nav mesh and this guy has moved towards us automatically.
‫But if I leave that nav mesh, he can no longer get any closer to me because he can't find the route.
‫He can't find a way of getting to me.
‫So what we're going to do is we in fact, I'm not sure that was what's actually going on here, because
‫probably what's happening is that he's getting within the acceptance radius of me and they're not trying
‫again.
‫So one way to check that would be to just remove this acceptance radius and recompile and then we can
‫go over and see if that's what's going on.
‫So yeah, he comes right up to me if I move away.
‫Well, he basically forgot that command.
‫So what we want to do is do this in tic, because basically once he reaches me, he gives up on the
‫idea of chasing me.
‫So let's move this over to tic.
‫This isn't the ideal way to do it, but that's what we're going to do.
‫Just for now, I'm going to copy the signature of Tic from actor H, and I know that it goes in the
‫public section, so I'm going to create a public section at the top.
‫Copying the signature, make it an override, just safety, and then implement it over in the C++ and
‫move our move actor in to tick and the acceptance radius still of two metres that's try this now and
‫obviously it's complaining that we don't have a player -- over there.
‫So let's go and make sure we're getting hold repeating this line that gets hold of the first player
‫-- over in attic as well.
‫And now we should be able to test it out properly, do an alt pig into the world.
‫He comes and gets us within two meters.
‫I move away from him and I'll look at that.
‫He's not even aiming at me properly this time, but he is trying to follow along.
‫But as soon as I leave that nav mesh, he no longer knows how to find me.
‫So let's fix that up, shall we?
‫We're going to go to an nav mesh bounce volume.
‫If I can select it.
‫There we go.
‫And then we want to really zoom out here to try and encompass the whole of our level.
‫It looks a bit janky on the outside this level, but that's just the way things often work, is that
‫you build the level to be viewed from the inside, not from the outside.
‫So let's make this much wider.
‫Let's make it much taller so that it encompasses all of the level and just drag it out so that all the
‫extents of the level here are covered.
‫Just make it a little bit wider, a little bit longer too, and just make sure all of this is encompassed
‫fully.
‫And you can see the green has appeared as it's calculated the nav mesh.
‫And let's just make sure that the nav measure is going down low enough that it's covering the lowest
‫extents of our map seems to be covering it now.
‫So if we go ahead and we can hide and nav mesh now that we have set it all up and we can do an alt p
‫to go ahead and play and he can find us and follow us pretty much anywhere that we go within this level.
‫You can see that our trusted loyal servant is following along behind us wherever we choose to go.
‫He is just tailing us and trailing us, which is very annoying.
‫But he is able to do that.
‫Well, some stuff.
‫So in this lecture we have seen how we can create our NAV measures and how we can use them to get our
‫air to follow us around the level.
‫Next lecture we're going to loop back around to this aming fix the bug and check line of sight so that
‫we don't necessarily always chase the player around.
‫See there.
‫And I've just noticed one silly little mistake that I have made here, which is that I'm not calling
‫to super colon colon tic.
‫So that is actually why when you sometimes you get these weird unexplained bugs, if you're not calling
‫to super, then things don't always work as expected.
‫That's why the focus had stopped working, because essentially we had disabled tic on a high controller,
‫which is no good.
‫If you enable that, then everything should work as normal with the setting focus.