Okay.
So far we have our chompers moving around independently when you click on the collider, all terrain
that's in here.
Now, if I have less chompers than you do in your scene, it's because my version of unity crash between
the last lecture and this one.
And I may not have had it saved, so I've just sort of put it all back together again.
What we're going to do in this lecture is to grab hold of combat.
Jane, who is a prefab down in your assets folder that came with a starter file and what can combat
Jane do?
Well, she can act as your player character, so let's just press play with her in the scene.
Now, if you use the arrow keys, then you can actually move her around like this.
Now, what we want to do is to modify the goal location of our chompers so that they basically follow
her around rather than where you click.
So to do that is fairly straightforward.
We're going to open up our eye controller code, and the eye controller code needs to know about Jane
or our character who's going to be our target.
So up here we're going to put in a public game object target, which we will have to pass through in
the inspector.
And then what we do down here in our update is to use Jane as our set destination.
So all we need to do in here is just go agent dot set destination and our destination will be our target
dot transform dot position like that.
Okay to easy save that.
Let's go back into unity now.
We need to grab hold of everybody who needs to have Jane attributed to them.
So let's just move.
Chopper one that's just up there and this select all of these guys and then find their A.I. component,
which it might not let you do unless they're all exactly the same.
And in this case, my chopper doesn't have that on there, most likely because of my crash that I had
before.
Okay.
Now the others should all have that on their.
Yeah, they do.
So now if I select them all, I should have an air controller which is up here, the target which is
Jane up here.
We're just going to select Jane and drop her onto the target so that they've all got that.
And we're just going to check that that went in.
Sometimes this doesn't always do what you think it's going to do.
Okay, now my chompers have two lots of R scripts on them, or at least some of them do.
So let's just remove the second one.
Okay?
We're all good.
The joys of developing.
Okay, let's press play and now try this out the distance that they can get to her.
You might want to change that as well.
You can see that they're right on top of her there.
If we move out, they're going to follow her around, which is quite neat.
So like not pet chompers, but they're all very, very cloudy, aren't they?
So something you can set in your agents.
If we select all these guys, it's come over into a mesh.
You've got this stopping distance which is here.
They're going to stop when they get to zero, which is like perfect accuracy on the waypoint that you've
told them to go to.
If they don't need to be on there, then you could set it a little bit further away, like two for example.
Okay, so now when we press play, they'll actually give her a little bit of breathing space.
They'll get within two and then they're sort of like, stop, and then she can run away again.
So she's basically got all her Ciampa minions with her.
And of course, they're going to be able to go the same places that they could before.
Okay.
So if you want to test, if Jane can run over onto this big rock here and then the big green chopper
will come with her.
Let's just select this rock and have a look over in the hierarchy.
This rock does not have any colliders on it.
And Jane is a collider sort of based character with a capsule collider which needs a collider in order
for her to come up.
Now, the terrain has a train collider on it, so that's fine.
This rock doesn't let's just add it in the inspector.
We want a, I guess a mesh collider for that.
Make sure it sets it to rock one, which is what it is here.
Okay.
Now, in the game view, you want to make sure that your camera is in the right space, that you can
actually see that rock over there.
So just maybe move it around a little bit.
And then up because we want her to be able to come over here.
Okay.
And with that done, let's press play and we'll see if we can get her to come up onto this rock.
So I'm going to run this way and then try and pop up here.
Okay.
So the little pink guys won't be able to get up here, but the big green chopper guy can get up there.
Now sometimes your meshes that are generated will not be perfect.
And they'll also be big steps like this that you might want your characters to be able to get up.
So if there's a big gap somewhere and you want them to be able to jump over that gap or jump up on something,
then you can set that as an off mesh link.
Okay.
Now, to do that as a demo, I'm going to get Ciampa to be able to jump up onto this particular rock
here.
So what we need to do is to come over to our break tab, set the drop height.
In this case, we'll go for five.
And the drop distance, jump distance, I mean, as five as well.
Then we're going to go into the object and in here we have to set everything.
We want to have an off mesh link to and tick that box.
In this case, it's this rock, so we're going to select it and tick off mesh links.
Now, at the same time, we could get the terrain and make sure that it has off mesh links as well so
they can jump up and back again.
And then we go back into Bake and we hit the bake key.
Now can you see what we ended up with?
It might have been a bit subtle, but you can see these like rings and these arrows which are showing
where you can jump from.
Now, there's kind of a waterfall here of them.
They're very, very subtle in this particular view.
Hopefully you'll be able to see them much clearer on your own computer screen, but they are just there.
So this should allow Ciampa to come along and jump up and down from that rock.
So let's press play and we'll get Jane to go back over there again.
I might go the long way, so go on this way.
And then we're going to turn around and come up here.
And over to here, our chomp up seat is going to.
Oh.
Can't quite get his physics.
There he goes.
Up becomes.
Now if she jumps off of here he should just follow straight down as he did.
So he always just able to jump and slip off of that rock without hurting himself.
And that's the off mesh links.
So as I said, they're really good for any vertical things that you want to jump up on or down from
and any gaps that might have appeared in the mesh that you really didn't want there or that unity hasn't
been able to sort of generate properly from the structure of your mesh.
And you can see quite a bit of them going on actually from here.
You can see that it's calculated, a whole bunch of them around here across these areas that weren't
accessible before because it had had blocked them out.
Okay.
So that's following a character and making the nav mesh just a little bit more flexible of where you
can actually traverse from.