WEBVTT

00:14.110 --> 00:20.080
OK, in this video, I'm going to give you a little bit of a challenge, what I would like you to do

00:20.080 --> 00:29.290
is to keep the pursuit and the hoarding mechanics like we've got them, but include now a range.

00:29.500 --> 00:37.790
And if the cop is outside of a distance of 10 from the robber, then the robber should just wander around.

00:37.810 --> 00:40.460
So let me show you that in action.

00:40.900 --> 00:43.960
OK, so he's now going to hide.

00:46.630 --> 00:53.140
And you can see over in this view over here, he's just hidden around the back and here he comes around

00:53.140 --> 00:53.640
there.

00:54.730 --> 01:01.750
And if I can just you can see he's gone into wonder now what I'm going to do is just try and get him

01:01.750 --> 01:05.200
to follow me out here and I'll stay close to him.

01:05.980 --> 01:08.230
So here he comes following.

01:09.280 --> 01:11.290
I don't want to turn around and spook him.

01:12.260 --> 01:17.770
OK, now I'm just going to go really fast to get out of a distance of ten, at which point he's just

01:17.770 --> 01:20.200
going to wander around and do his own thing.

01:20.200 --> 01:21.550
So he just goes into a wander.

01:21.970 --> 01:29.020
But then if I come back close in again like that, he's going to decide he needs to go and hide from

01:29.020 --> 01:30.760
me, which he's just done.

01:32.280 --> 01:32.640
They're.

01:34.210 --> 01:39.760
And if I turn around when he comes back out to have a look now, he's just going to go off and wonder

01:39.760 --> 01:43.320
because that distance is 10, obviously around that area.

01:44.880 --> 01:53.670
OK, so see if you can pull up together, pull the video now, and when we come back, I will show you

01:53.670 --> 01:55.050
how I implemented it.

01:56.010 --> 01:56.430
All right.

01:56.430 --> 01:58.200
How did you go with that?

01:58.320 --> 02:05.340
Well, the first thing that you're going to need is to determine if the cop is out of range.

02:05.490 --> 02:08.750
And for that, I'm going to create another method.

02:08.760 --> 02:16.400
So it's going to return a bull bull target in range, we'll call it.

02:16.560 --> 02:22.290
Now, you could actually pass that through a particular range if you wanted to set that up so you could

02:22.290 --> 02:27.810
have a variable and use it for other conditions down in your update.

02:27.810 --> 02:33.420
But we're not doing that or we're going to go as if vector three distance.

02:35.040 --> 02:48.900
Between this dot transform dot position and the target dot transformed, what position is.

02:49.840 --> 02:52.750
Less than 10.

02:54.490 --> 02:56.350
Then we will return, true.

02:59.250 --> 03:02.010
Otherwise, we will return false.

03:03.440 --> 03:09.080
OK, so that's our target in range now we just have to implement that down in our update.

03:09.530 --> 03:11.270
So where are we going to put it?

03:11.300 --> 03:21.260
Well, if the target is out of range, then it really doesn't depend on whether you can see something

03:21.260 --> 03:25.360
or whether the target can see you were just having the simple out of range.

03:25.370 --> 03:29.140
So it really needs to be the first thing in your if statement.

03:29.660 --> 03:44.450
So we're going to have if not target in range, then what we can do in here is wonder and I'm not going

03:44.450 --> 03:50.870
to sit a cool down for that particular behavior because I want them to immediately stop wondering if

03:51.830 --> 03:57.660
the agent gets into range and it can go and then hide and then do all these other things.

03:57.980 --> 03:59.930
Now we need to put an else down here.

03:59.930 --> 04:06.800
So we're checking if we're out of range, then we want the wandering to happen pretty much no matter

04:06.800 --> 04:07.200
what.

04:07.220 --> 04:08.900
Which is why it is up the top.

04:08.900 --> 04:14.300
And if because we have Elst it with these other things, they're not going to try and overwrite it if

04:14.300 --> 04:17.480
it's already happening or if this is a true condition.

04:18.020 --> 04:19.310
And that's pretty much it.

04:19.340 --> 04:20.810
So very simple.

04:20.840 --> 04:27.980
We've only added like one, two, three, four, five, six, seven, eight, nine, about ten lines

04:27.980 --> 04:29.720
in here just to get that done.

04:30.080 --> 04:34.060
And the majority of it was just in our condition that we put up here.

04:34.460 --> 04:43.970
So I'm just going to save that, go back to unity and we can play and try that out with our little agent,

04:44.390 --> 04:46.240
which we're looking at to start with.

04:46.700 --> 04:53.150
And so if we now go out here, then he's just going to go off and wander around.

04:54.440 --> 05:00.860
And if we come back into range, he's going to go and hide, which you can't see because he's out here

05:00.860 --> 05:01.180
now.

05:02.330 --> 05:04.400
So we've got that complex behavior.

05:04.400 --> 05:11.120
And now you might like to actually duplicate your robot and create a few versions of it so you can actually

05:11.120 --> 05:13.250
see what it's like if you've got lots of agents.

05:13.250 --> 05:20.480
So we're just going to select him and control D to make a copy, hit the cage to make sure you can just

05:20.480 --> 05:21.470
move them out.

05:28.180 --> 05:31.540
I don't know how many we want, as many as you like, really.

05:32.060 --> 05:39.430
OK, and now let's press play and they're all going to go and hide.

05:40.000 --> 05:43.210
Or actually the ones at the far end have gone and wandered.

05:43.210 --> 05:44.220
Some of them are hiding.

05:44.800 --> 05:52.650
So if we take the cop over to these guys, we can actually make them hide from him.

05:52.660 --> 05:54.190
They go and hide behind that tree.

06:00.170 --> 06:04.970
See if I can force them to come around the other side and hide from him.

06:07.720 --> 06:15.460
So he comes are they hiding the cops behind the house and he obviously has no colliders, he can go

06:15.460 --> 06:17.380
through the house, so.

06:22.760 --> 06:27.350
Let's just turn this around, because most of the actions all happening over in that back area over

06:27.350 --> 06:36.710
there and just the or is he these guys are going to go hide behind that tree over there.

06:37.350 --> 06:43.760
And if I turn around, all those guys will go back and hide over there behind the house on the other

06:43.760 --> 06:44.390
side.

06:45.050 --> 06:46.960
And then others are just going to wander.

06:48.260 --> 06:51.590
And we have some nice, complex behavior.

06:51.620 --> 06:56.660
Now, if I get my cup and bring him back around the front and.

07:01.180 --> 07:06.640
It's getting totally out of range of everybody, then they should just all go wandering off on their

07:06.640 --> 07:07.030
own.

07:08.050 --> 07:14.140
As you can see, they're doing their happily wandering around and if they ever wander over near the

07:14.140 --> 07:19.280
cop that they are like that, they discover that he suddenly exists.

07:19.720 --> 07:27.120
I mean, if we go like this, then they'll start to sneak up on him, just put him over here.

07:28.510 --> 07:34.930
So when they wander within range, which of course they won't because I'm wanting them to right now.

07:43.570 --> 07:44.040
Here we go.

07:44.070 --> 07:52.410
So a few of them have now snuck up behind him and he come a few others sneaking up over here, but if

07:52.410 --> 08:00.510
I turn around, I'm going to force them all to run away and go and hide from me because I've noticed

08:00.510 --> 08:00.840
them.

08:06.370 --> 08:10.760
I like how they all had to have a look around the corner there to see if he was still OK.

08:11.100 --> 08:17.850
So that's another complex behavior that we've now added in there to our sneaky sort of pursue.

08:17.850 --> 08:26.370
We've got wondering and you can put evade in there if you want to put that instead of hiding, some

08:26.370 --> 08:28.890
could evade or some of the time he'd go and hide.

08:29.100 --> 08:35.550
Or if you're not close enough to a particular hiding position, which is something else you could program

08:35.550 --> 08:38.100
in, you could then go into the evade mode.

08:38.100 --> 08:44.670
So if you can't find any way to hide, to start to evade many possibilities now that you have that simple

08:44.670 --> 08:47.520
set of tools for these agents.
