WEBVTT

00:06.650 --> 00:07.210
Okay.

00:07.220 --> 00:10.720
In this video, I'm going to give you a little bit of a challenge.

00:10.730 --> 00:19.880
What I would like you to do is to keep the pursuit and the hiding mechanics like we've got them, but

00:19.880 --> 00:21.950
include now a range.

00:21.950 --> 00:29.720
And if the cop is outside of a distance of ten from the robber, then the robber should just wander

00:29.720 --> 00:30.320
around.

00:30.320 --> 00:33.200
So let me show you that in action.

00:33.440 --> 00:33.610
Okay.

00:33.740 --> 00:36.740
So he's now going to hide.

00:39.210 --> 00:42.690
And you can see him over in this view over here.

00:42.690 --> 00:44.400
He's just hidden around the back.

00:44.730 --> 00:46.350
And here he comes around there.

00:47.310 --> 00:52.380
And if I can just you can see he's going into Wanda.

00:52.380 --> 00:57.960
Now, what I'm going to do is just try and get him to follow me out here and I'll stay close to him.

00:58.440 --> 01:01.020
So here he comes, following.

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

01:04.740 --> 01:04.930
Okay?

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

01:10.290 --> 01:12.750
going to wander around and do his own thing.

01:12.750 --> 01:14.280
So he just goes into a wander.

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

01:21.540 --> 01:23.610
me, which he's just done.

01:24.860 --> 01:25.340
There.

01:26.720 --> 01:29.910
And then if I turn around when he comes back out to have a look.

01:30.740 --> 01:36.020
No, he's just going to go off and wander because that distance is ten, obviously, around that area.

01:37.790 --> 01:42.290
So see if you can pull that together.

01:42.980 --> 01:44.150
Pause the video now.

01:44.150 --> 01:47.870
And when we come back, I will show you how I implemented it.

01:48.560 --> 01:48.970
All right.

01:48.980 --> 01:50.780
How did you go with that?

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

01:58.010 --> 02:01.300
And for that, I'm going to create another method.

02:01.310 --> 02:08.260
So it's going to return a bull bull target in range.

02:08.270 --> 02:09.000
Well, we'll call it.

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

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

02:20.330 --> 02:21.380
But we're not doing that.

02:21.740 --> 02:26.210
All we're going to go is if vector three dot distance.

02:27.570 --> 02:45.540
Between this dot transform dot position and the target dot transform dot position is less than ten.

02:46.980 --> 02:48.420
Then we will return.

02:48.420 --> 02:49.110
True.

02:51.840 --> 02:53.550
Otherwise we will return.

02:53.910 --> 02:54.780
False.

02:56.090 --> 02:56.270
Okay.

02:56.400 --> 02:58.370
So that's our target in range.

02:58.380 --> 03:01.870
Now we just have to implement that down in our update.

03:01.890 --> 03:03.810
So where are we going to put it?

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

03:13.800 --> 03:15.640
or whether the target can see you.

03:15.640 --> 03:21.870
We're just having the simple out of range, so it really needs to be the first thing in your if statement.

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

03:36.510 --> 03:42.930
going to set a cooldown for that particular behavior because I want them to immediately stop wandering.

03:42.930 --> 03:50.700
If the agent gets into range and they can go and then hide and then do all these other things, now

03:50.700 --> 03:52.470
we need to put an else down here.

03:52.470 --> 03:55.440
So we're checking if we're out of range.

03:55.440 --> 04:01.440
Then we want the wandering to happen pretty much no matter what, which is why it is up at the top.

04:01.440 --> 04:07.020
And because we've lost it with these other things, they're not going to try and overwrite it if it's

04:07.020 --> 04:10.170
already happening or if this is a true condition.

04:10.440 --> 04:11.850
And that's pretty much it.

04:11.850 --> 04:13.380
So very simple.

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

04:20.490 --> 04:22.470
in here just to get that done.

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

04:26.790 --> 04:35.880
So I'm just going to save that, go back to Unity and we can press play and try that out with our little

04:35.880 --> 04:39.000
agent, which we're looking at to start with.

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

04:46.980 --> 04:53.400
And if we come back into range, he's going to go on hide, which you can't see because he's over here

04:53.400 --> 04:53.880
now.

04:54.750 --> 05:01.950
So we've got that complex behavior and now you might like to actually duplicate your robot and create

05:01.950 --> 05:05.790
a few versions of it so you can actually see what it's like if you've got lots of agents.

05:05.790 --> 05:12.840
So we're just going to select him and control D to make a copy, hit the W key to make sure you can

05:12.840 --> 05:14.220
just move them out.

05:20.770 --> 05:22.330
I don't know how many we want.

05:22.360 --> 05:23.680
As many as you like.

05:23.680 --> 05:24.280
Really?

05:24.550 --> 05:25.110
Okay.

05:25.120 --> 05:28.570
And now let's press play.

05:29.380 --> 05:32.200
And they're all going to go and hide.

05:32.500 --> 05:33.010
What?

05:33.010 --> 05:35.710
Actually, the ones at the far end have gone and wandered.

05:35.710 --> 05:36.940
Some of them are hiding.

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

05:45.190 --> 05:46.900
They go and hide behind that tree.

05:52.710 --> 05:57.750
See if I can force them to all come around the other side and hide from him.

06:00.260 --> 06:01.080
So he comes a heap.

06:01.100 --> 06:04.280
They're hiding the cops behind the house.

06:06.020 --> 06:07.700
And he obviously has no colliders.

06:07.700 --> 06:08.990
He can go through the house.

06:09.440 --> 06:10.130
So.

06:15.370 --> 06:19.900
Let's just turn this around, because most of the action's all happening over in that back area over

06:19.900 --> 06:20.470
there.

06:20.740 --> 06:26.800
And just put the cop where these guys are going to go.

06:26.830 --> 06:29.440
Hide behind that tree over there.

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

06:36.310 --> 06:37.120
side.

06:37.570 --> 06:39.760
And then others are just going to wander.

06:40.840 --> 06:44.150
And we have some nice, complex behavior.

06:44.170 --> 06:49.480
Now, if I get my cop and bring him back around the front and.

06:53.830 --> 06:59.740
Scared him totally out of range of everybody, then they should just all go wandering off on their own.

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

07:06.700 --> 07:12.160
cop that they are like that they discover that he's suddenly exist.

07:12.280 --> 07:19.870
Maybe if we go like this, then they'll start to sneak up on him and just put him over here.

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

07:36.030 --> 07:36.590
Here we go.

07:36.600 --> 07:39.840
So a few of them have now snuck up behind him.

07:39.840 --> 07:43.830
And here come a few others sneaking up over here.

07:44.010 --> 07:51.810
But if I turn around, I'm going to force them all to run away and go and hide from me.

07:51.840 --> 07:53.550
Because I've noticed them.

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

08:02.890 --> 08:03.460
Okay.

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

08:10.360 --> 08:18.910
We've got wandering and you can put a vade in there if you want to put that instead of hiding, some

08:18.910 --> 08:21.580
could evade or some of the time you can go and hide.

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

08:28.090 --> 08:30.580
in, you could then go into the evade mode.

08:30.580 --> 08:36.520
So if you can't find anywhere to hide, just start to evade many possibilities now that you have that

08:36.520 --> 08:40.270
simple set of tools for these agents.
