WEBVTT

00:06.590 --> 00:07.100
Okay.

00:07.100 --> 00:15.470
So far we have our chompers moving around independently when you click on the collider, all terrain

00:15.470 --> 00:16.350
that's in here.

00:16.370 --> 00:22.400
Now, if I have less chompers than you do in your scene, it's because my version of unity crash between

00:22.400 --> 00:24.230
the last lecture and this one.

00:24.230 --> 00:28.460
And I may not have had it saved, so I've just sort of put it all back together again.

00:28.550 --> 00:33.320
What we're going to do in this lecture is to grab hold of combat.

00:33.320 --> 00:41.390
Jane, who is a prefab down in your assets folder that came with a starter file and what can combat

00:41.390 --> 00:41.830
Jane do?

00:41.840 --> 00:47.750
Well, she can act as your player character, so let's just press play with her in the scene.

00:47.750 --> 00:54.650
Now, if you use the arrow keys, then you can actually move her around like this.

00:55.760 --> 01:03.770
Now, what we want to do is to modify the goal location of our chompers so that they basically follow

01:03.770 --> 01:06.440
her around rather than where you click.

01:06.590 --> 01:09.650
So to do that is fairly straightforward.

01:09.650 --> 01:17.750
We're going to open up our eye controller code, and the eye controller code needs to know about Jane

01:17.750 --> 01:20.480
or our character who's going to be our target.

01:20.480 --> 01:29.540
So up here we're going to put in a public game object target, which we will have to pass through in

01:29.540 --> 01:30.830
the inspector.

01:31.070 --> 01:38.720
And then what we do down here in our update is to use Jane as our set destination.

01:38.720 --> 01:48.350
So all we need to do in here is just go agent dot set destination and our destination will be our target

01:48.890 --> 01:54.440
dot transform dot position like that.

01:54.470 --> 01:57.260
Okay to easy save that.

01:57.440 --> 01:59.450
Let's go back into unity now.

01:59.450 --> 02:05.540
We need to grab hold of everybody who needs to have Jane attributed to them.

02:05.540 --> 02:06.590
So let's just move.

02:06.590 --> 02:15.680
Chopper one that's just up there and this select all of these guys and then find their A.I. component,

02:15.830 --> 02:20.360
which it might not let you do unless they're all exactly the same.

02:21.200 --> 02:28.190
And in this case, my chopper doesn't have that on there, most likely because of my crash that I had

02:28.190 --> 02:29.030
before.

02:29.210 --> 02:29.630
Okay.

02:29.660 --> 02:32.090
Now the others should all have that on their.

02:32.090 --> 02:32.630
Yeah, they do.

02:32.630 --> 02:38.810
So now if I select them all, I should have an air controller which is up here, the target which is

02:38.810 --> 02:40.400
Jane up here.

02:40.400 --> 02:46.520
We're just going to select Jane and drop her onto the target so that they've all got that.

02:46.520 --> 02:48.980
And we're just going to check that that went in.

02:49.790 --> 02:53.540
Sometimes this doesn't always do what you think it's going to do.

02:53.720 --> 02:59.510
Okay, now my chompers have two lots of R scripts on them, or at least some of them do.

02:59.600 --> 03:04.010
So let's just remove the second one.

03:04.460 --> 03:04.970
Okay?

03:04.970 --> 03:05.690
We're all good.

03:05.690 --> 03:07.370
The joys of developing.

03:07.400 --> 03:14.690
Okay, let's press play and now try this out the distance that they can get to her.

03:14.690 --> 03:16.040
You might want to change that as well.

03:16.040 --> 03:18.140
You can see that they're right on top of her there.

03:18.140 --> 03:22.040
If we move out, they're going to follow her around, which is quite neat.

03:22.040 --> 03:27.440
So like not pet chompers, but they're all very, very cloudy, aren't they?

03:27.440 --> 03:30.590
So something you can set in your agents.

03:30.590 --> 03:33.560
If we select all these guys, it's come over into a mesh.

03:33.560 --> 03:36.170
You've got this stopping distance which is here.

03:36.200 --> 03:42.440
They're going to stop when they get to zero, which is like perfect accuracy on the waypoint that you've

03:42.440 --> 03:43.850
told them to go to.

03:44.030 --> 03:50.810
If they don't need to be on there, then you could set it a little bit further away, like two for example.

03:51.230 --> 03:56.180
Okay, so now when we press play, they'll actually give her a little bit of breathing space.

03:56.180 --> 04:01.340
They'll get within two and then they're sort of like, stop, and then she can run away again.

04:04.280 --> 04:09.230
So she's basically got all her Ciampa minions with her.

04:09.230 --> 04:15.320
And of course, they're going to be able to go the same places that they could before.

04:17.060 --> 04:17.410
Okay.

04:17.420 --> 04:25.850
So if you want to test, if Jane can run over onto this big rock here and then the big green chopper

04:25.850 --> 04:26.720
will come with her.

04:26.750 --> 04:32.900
Let's just select this rock and have a look over in the hierarchy.

04:32.930 --> 04:37.520
This rock does not have any colliders on it.

04:37.550 --> 04:44.210
And Jane is a collider sort of based character with a capsule collider which needs a collider in order

04:44.210 --> 04:45.500
for her to come up.

04:45.620 --> 04:49.590
Now, the terrain has a train collider on it, so that's fine.

04:49.610 --> 04:52.370
This rock doesn't let's just add it in the inspector.

04:52.370 --> 04:56.360
We want a, I guess a mesh collider for that.

04:56.540 --> 05:01.490
Make sure it sets it to rock one, which is what it is here.

05:01.790 --> 05:02.330
Okay.

05:02.330 --> 05:07.040
Now, in the game view, you want to make sure that your camera is in the right space, that you can

05:07.040 --> 05:10.580
actually see that rock over there.

05:10.580 --> 05:14.330
So just maybe move it around a little bit.

05:18.170 --> 05:22.250
And then up because we want her to be able to come over here.

05:22.340 --> 05:22.870
Okay.

05:22.880 --> 05:28.790
And with that done, let's press play and we'll see if we can get her to come up onto this rock.

05:28.790 --> 05:35.360
So I'm going to run this way and then try and pop up here.

05:35.390 --> 05:35.960
Okay.

05:36.350 --> 05:44.240
So the little pink guys won't be able to get up here, but the big green chopper guy can get up there.

05:55.960 --> 06:00.940
Now sometimes your meshes that are generated will not be perfect.

06:00.940 --> 06:07.240
And they'll also be big steps like this that you might want your characters to be able to get up.

06:07.480 --> 06:13.780
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,

06:13.780 --> 06:17.530
then you can set that as an off mesh link.

06:17.560 --> 06:17.870
Okay.

06:17.890 --> 06:26.350
Now, to do that as a demo, I'm going to get Ciampa to be able to jump up onto this particular rock

06:26.350 --> 06:27.040
here.

06:27.190 --> 06:34.690
So what we need to do is to come over to our break tab, set the drop height.

06:35.080 --> 06:36.820
In this case, we'll go for five.

06:36.820 --> 06:41.710
And the drop distance, jump distance, I mean, as five as well.

06:42.040 --> 06:47.050
Then we're going to go into the object and in here we have to set everything.

06:47.050 --> 06:51.080
We want to have an off mesh link to and tick that box.

06:51.100 --> 06:58.600
In this case, it's this rock, so we're going to select it and tick off mesh links.

06:58.690 --> 07:05.800
Now, at the same time, we could get the terrain and make sure that it has off mesh links as well so

07:05.800 --> 07:07.630
they can jump up and back again.

07:07.630 --> 07:11.350
And then we go back into Bake and we hit the bake key.

07:11.380 --> 07:13.990
Now can you see what we ended up with?

07:13.990 --> 07:23.170
It might have been a bit subtle, but you can see these like rings and these arrows which are showing

07:23.170 --> 07:24.510
where you can jump from.

07:24.520 --> 07:27.610
Now, there's kind of a waterfall here of them.

07:27.730 --> 07:30.400
They're very, very subtle in this particular view.

07:30.430 --> 07:37.050
Hopefully you'll be able to see them much clearer on your own computer screen, but they are just there.

07:37.060 --> 07:43.720
So this should allow Ciampa to come along and jump up and down from that rock.

07:43.720 --> 07:50.560
So let's press play and we'll get Jane to go back over there again.

07:51.580 --> 07:55.540
I might go the long way, so go on this way.

07:55.540 --> 07:58.870
And then we're going to turn around and come up here.

08:02.150 --> 08:05.550
And over to here, our chomp up seat is going to.

08:05.570 --> 08:06.270
Oh.

08:06.350 --> 08:07.520
Can't quite get his physics.

08:07.520 --> 08:07.970
There he goes.

08:07.970 --> 08:08.590
Up becomes.

08:08.600 --> 08:12.920
Now if she jumps off of here he should just follow straight down as he did.

08:12.920 --> 08:17.660
So he always just able to jump and slip off of that rock without hurting himself.

08:17.810 --> 08:20.030
And that's the off mesh links.

08:20.030 --> 08:27.020
So as I said, they're really good for any vertical things that you want to jump up on or down from

08:27.020 --> 08:34.100
and any gaps that might have appeared in the mesh that you really didn't want there or that unity hasn't

08:34.100 --> 08:38.810
been able to sort of generate properly from the structure of your mesh.

08:38.810 --> 08:43.730
And you can see quite a bit of them going on actually from here.

08:43.730 --> 08:50.060
You can see that it's calculated, a whole bunch of them around here across these areas that weren't

08:50.210 --> 08:54.290
accessible before because it had had blocked them out.

08:54.410 --> 08:54.890
Okay.

08:54.890 --> 09:01.670
So that's following a character and making the nav mesh just a little bit more flexible of where you

09:01.670 --> 09:03.710
can actually traverse from.
