WEBVTT

00:06.400 --> 00:10.210
Welcome back to part two of Creating a City Crowd.

00:10.240 --> 00:17.920
Now, what I want to do in this one is to get the people moving up and down along a potential sidewalk

00:17.950 --> 00:22.920
that goes from here and up to this corner and then back down again.

00:22.930 --> 00:27.360
So we need to get three of our goal locations.

00:27.370 --> 00:30.790
So I'm going to grab them one by one.

00:30.790 --> 00:32.020
So there's one there.

00:32.020 --> 00:39.490
So if I hit the key on that can actually move that goal location and I'm going to put it up here, then

00:39.490 --> 00:46.990
I'll get the next one and I will put it down here in this corner.

00:48.570 --> 00:53.850
And then the next one I will put up the other end of the street.

00:53.850 --> 00:54.580
So up there.

00:54.600 --> 01:00.720
Now the remaining ones, these three here, we can actually delete.

01:00.720 --> 01:02.740
So we don't need those anymore.

01:02.790 --> 01:03.140
Okay.

01:03.150 --> 01:09.060
Now the people themselves, we want to sort of move them out of the road a little bit.

01:09.480 --> 01:18.210
So let's just move these guys back here and anybody who's sort of within that darker gray square, just

01:18.210 --> 01:23.520
move them out of the road because we're going to put some buildings into here and we actually don't

01:23.520 --> 01:25.890
want them in the road.

01:25.890 --> 01:28.200
So let me see if I can find each of these.

01:28.320 --> 01:31.950
Just drag them out and then this one.

01:33.310 --> 01:35.090
Drag her out there.

01:35.090 --> 01:35.450
Okay.

01:35.470 --> 01:38.100
So I think they're all outside of that realm.

01:38.110 --> 01:41.950
Now, we going to put in some buildings.

01:42.340 --> 01:47.710
So to do that over in the assets, if you come down and find the street folder resources folder, there's

01:47.710 --> 01:52.450
a prefabs folder and in there there's some buildings and some shops.

01:52.450 --> 01:57.520
Now the shops, if you grab that and drag that into your scene, you'll see that it's actually quite

01:57.520 --> 02:05.050
a large model and it will fit in that gray square.

02:05.200 --> 02:09.940
So let's just see if I can find that here.

02:10.450 --> 02:17.320
And we just want to make sure it intersects with that nav mesh so that we can use it to block the path

02:17.710 --> 02:19.660
of the agents.

02:19.660 --> 02:25.780
Now, there's also a building here that you can drag in, which is absolutely enormous, and it sits

02:25.780 --> 02:29.200
sort of inside of the street.

02:30.110 --> 02:32.060
Like this.

02:32.770 --> 02:35.650
Now it's really only for aesthetics.

02:35.830 --> 02:40.630
You could, of course, just create all of this out of basic cubes.

02:40.660 --> 02:44.440
You might want to bring that city down just a little bit more.

02:44.440 --> 02:47.110
So let's see where those buildings have gone.

02:47.860 --> 02:49.660
And they're just here.

02:49.930 --> 02:51.520
Bring down the Y.

02:52.890 --> 02:53.760
A little bit.

02:53.910 --> 02:54.480
Okay.

02:54.480 --> 03:03.930
So now what we will do is just select the buildings and the shops and you want to come over and make

03:03.930 --> 03:05.580
sure that they are navigation static.

03:05.580 --> 03:11.940
So drop down that box and you're looking to set them to navigation static.

03:11.940 --> 03:12.390
Yes.

03:12.390 --> 03:14.280
You want to change all of the children.

03:14.310 --> 03:19.020
Then while we're here, we'll go to the navigation and then we'll click on Bake.

03:19.650 --> 03:26.970
Now you'll be able to see immediately that our nav mesh gets baked around here.

03:26.970 --> 03:31.110
So you can actually see there's a bit of a gutter around there.

03:31.110 --> 03:31.770
Okay.

03:31.770 --> 03:40.500
So at this point, if we press play, we should get the crowd walking along the sidewalk.

03:40.500 --> 03:43.320
They're up to each goal.

03:44.430 --> 03:45.150
So here they go.

03:45.150 --> 03:47.160
Let's come out to the same view and have a look.

03:47.160 --> 03:48.960
So they're going to walk to this goal.

03:48.960 --> 03:54.120
They're going to go up that end, and then then they will pick another random goal and come back up

03:54.120 --> 03:55.230
to this end.

03:55.230 --> 03:57.840
Now they're going to select the shortest path.

03:57.840 --> 04:01.410
So the shortest path from up here is going to be to come back again.

04:01.410 --> 04:03.240
And you can see these guys are doing the same thing.

04:03.240 --> 04:04.710
So they're coming back now.

04:04.710 --> 04:12.180
Currently, they're walking all at the same speed, same animation.

04:12.330 --> 04:17.100
So they're kind of all in step with each other, which doesn't make them look very natural.

04:17.100 --> 04:22.470
So let's just fix their animation so that they start at random times.

04:22.830 --> 04:32.400
So what we're going to do is to go into one of the agents and find their animation, which is this controller

04:32.400 --> 04:39.030
here, and we want to select the walking animation inside of this looking animation.

04:39.030 --> 04:42.060
Over in the inspector, you'll find that there's a cycle offset.

04:42.060 --> 04:48.510
Now this can be set to a small offset, which will make them start their animations in slightly different

04:48.510 --> 04:49.530
places.

04:49.530 --> 04:55.530
So to do that, we need to create another parameter over on this side and the parameters you want to

04:55.530 --> 04:59.700
hit the plus button and add a float.

04:59.700 --> 05:06.450
We're going to call this our W offset, which stands for our walk off set.

05:06.480 --> 05:14.490
Then the walking animation here we can come over and inside of this cycle offset, click on the parameter

05:14.490 --> 05:18.450
box and then you can select W offset there.

05:18.810 --> 05:22.950
Now you need to actually set this within the code as well to make it work.

05:22.950 --> 05:30.540
So back to our assets, open up your script and what we're going to do underneath our is walking is

05:30.540 --> 05:41.640
put an m dot set float w offset in quotes, same spelling and capitalization and we'll set it to a random

05:41.880 --> 05:51.240
range between 0.0 F and 1.0 F, which will start the animations at slightly different locations.

05:51.240 --> 05:51.600
Right?

05:51.600 --> 05:52.590
So save that.

05:52.590 --> 05:54.600
Let's go back into unity.

05:54.600 --> 06:00.840
We'll press play and have a look at the effect that that has on the walking.

06:02.330 --> 06:02.530
Okay.

06:02.690 --> 06:08.390
So now they're not all in perfect step with each other, which looks a little bit more natural.

06:09.170 --> 06:14.420
And we can also add in a speed multiplier so that they move at different speeds.

06:14.420 --> 06:23.870
So back in the animator, we'll add in another float and we will call this one a speed malt like that.

06:23.870 --> 06:26.870
Now we'll select the walk and then over an inspector.

06:26.870 --> 06:28.340
There's a speed value here.

06:28.340 --> 06:37.820
You can actually click on parameter and multiply by speed malt, which will speed up the animation and

06:37.820 --> 06:39.650
how fast they're actually moving.

06:39.650 --> 06:45.410
So with that, let's go back into the script and we'll just add this in here.

06:45.410 --> 06:58.760
So we want to float speed multiplier equals random dot range 0.5, F and two and then we'll go.

06:58.760 --> 07:05.510
Adam Dot set float speed malt.

07:06.800 --> 07:07.440
Awesome.

07:07.700 --> 07:10.670
Now we've sped up the actual animation.

07:10.670 --> 07:12.590
We need to speed up the agent as well.

07:12.590 --> 07:19.070
So agent speed multiply equal with SN.

07:19.070 --> 07:22.220
So we're two places, we have to speed them up.

07:23.570 --> 07:30.290
Now let's go ahead and add a dynamic obstacle and we'll make it a first person controller.

07:30.290 --> 07:35.540
So attached to this lecture, there's a unity package called Characters Drag and drop that into your

07:35.540 --> 07:36.230
assets.

07:36.230 --> 07:38.930
It will create a standard assets folder.

07:38.930 --> 07:45.050
Once it's loaded, you'll get a few warnings because it uses some old things from the previous standard

07:45.050 --> 07:49.910
s package, which aren't actually used in here, but the scripts are still sort of integrated.

07:49.910 --> 07:51.920
You can just select the console and clear it.

07:51.920 --> 07:54.950
It's not going to affect the performance.

07:54.950 --> 07:59.030
Okay, now we want to go into our standard assets folder.

07:59.030 --> 08:05.750
Then we're going to go into characters first person prefabs and we want the controller.

08:05.750 --> 08:11.990
So just drag that into the street and then you might just want to lift it up a little bit.

08:12.900 --> 08:15.180
So that it's above the street level.

08:15.270 --> 08:15.750
Okay.

08:15.750 --> 08:21.600
So when we press play, you'll be able to move that around.

08:22.170 --> 08:28.140
And if we go back to the same view so we can actually see it and put this over here.

08:28.830 --> 08:33.370
You'll be able to look around with the mouse and then use the arrow keys to move.

08:33.390 --> 08:39.230
Now, currently you can see that the people are just going to walk straight through the character.

08:39.240 --> 08:43.580
They're not even going to be affected by bumping into it or anything like that.

08:43.590 --> 08:47.880
So instead what we're going to do is make it into a nav mesh obstacle.

08:47.880 --> 08:53.100
So come over into the controller in the inspector.

08:53.370 --> 09:02.220
We're going to roll up all of this stuff and we're going to add a nav mesh obstacle to it.

09:02.310 --> 09:04.110
Now it can have a size.

09:04.110 --> 09:07.920
If you have a look in my scene, you'll see that it's put a box around there.

09:07.950 --> 09:16.740
The controller is basically a capsule, so we can set that size to capsule, which will fit the current

09:16.740 --> 09:20.750
size of the controller, as you can see there.

09:20.760 --> 09:27.510
Now, of course, if it was a different size, you could resize it and recenter that actual capsule

09:27.510 --> 09:28.440
over in the inspector.

09:28.440 --> 09:30.570
So it fits a little bit better.

09:30.780 --> 09:38.700
Right now, what you're going to find when we press play is that we have a nav mesh obstacle and you

09:38.700 --> 09:42.420
can see that people are walking around it.

09:46.010 --> 09:52.820
Now to have a look at what this looks like from the first person point of view, if you select the camera

09:52.820 --> 09:59.840
that's in your scene just here, so this is the main camera and turn it off, it will then default to

09:59.840 --> 10:03.650
the camera that is on the first person character.

10:03.700 --> 10:04.070
Okay.

10:04.070 --> 10:10.790
So now if we press play, let's bring across this game view, you'll be able to walk among the people.

10:10.790 --> 10:16.430
But because you've got the capsule collider on there for the nav mesh, you'll actually be able to push

10:16.430 --> 10:17.900
them out of the way.

10:18.140 --> 10:24.860
So if we turn around and walk back into the crowd, you'll find that they go nicely around us.

10:24.950 --> 10:29.450
And so you can create these kinds of dynamic obstacles.

10:29.450 --> 10:34.280
Like, for example, you have a car that you drive down here or you can have a doorway that opens and

10:34.280 --> 10:35.060
closes.

10:35.060 --> 10:43.160
The nav mesh will recalculate the walking position of the characters so that they will basically avoid

10:43.160 --> 10:43.640
you.

10:43.850 --> 10:51.140
Okay, so that's a very simple way to create quite an effective crowd.
