WEBVTT

00:06.410 --> 00:14.210
So far, we've got one agent that can put together a string of actions to satisfy a single goal, and

00:14.210 --> 00:17.120
we can tell what's going on with those goals.

00:17.120 --> 00:22.820
If we look in the console at the moment, which gives us a little bit of an idea of the plans for the

00:22.820 --> 00:23.630
agent.

00:24.350 --> 00:32.540
In addition to this, I've created an attaches as a resource to this video Agent Visualizer.

00:32.540 --> 00:34.670
So if you download that.

00:35.500 --> 00:42.700
Zip, unzip it and then just drag and drop that folder into your assets.

00:42.730 --> 00:43.060
Hold on.

00:43.060 --> 00:47.960
First of all, we should stop pausing and playing drag and drop that in.

00:47.980 --> 00:51.400
So it's the agent visualizer here.

00:51.520 --> 00:58.750
Now, the Agent Visualizer has two scripts in it has one script, which is the agent visual that you

00:58.750 --> 01:02.440
can attach to any of your agents.

01:02.590 --> 01:08.920
And then there's a G agent editor that needs to go into a folder that's called editor.

01:08.920 --> 01:18.700
So go back to your assets and just create a new folder, call that editor and then open that up and

01:18.700 --> 01:23.500
grab that G agent editor and drag and drop that into editor.

01:23.770 --> 01:26.200
Looks like I already had editor in there.

01:26.830 --> 01:28.090
So that one's now empty.

01:28.090 --> 01:29.650
I'll just delete that.

01:30.250 --> 01:30.700
Okay.

01:30.700 --> 01:40.240
So now that we've got that, you can grab your G agent visual and if you click on your patient drag

01:40.240 --> 01:44.800
and drop that into the inspector.

01:45.340 --> 01:50.560
And then we're going to just make sure that we put these changes back to our prefab.

01:50.560 --> 01:56.980
So go up to the top of the inspector and where you've got overrides, just click on that and there's

01:56.980 --> 02:02.710
an apply all button next to it and that'll make sure that all of the patients that get spawn from your

02:02.710 --> 02:05.410
prefabs have the same things on them.

02:05.440 --> 02:13.090
Now this G agent visual actually uses inspector editor code, which I'm not going to go through in this

02:13.090 --> 02:13.990
course.

02:14.500 --> 02:17.820
But if you're interested, I guess you can have a dig around in the code.

02:17.830 --> 02:26.560
Now, if we press play, you'll see that and then pause it that this agent visual actually shows you

02:26.560 --> 02:34.300
what the current action is, what the goals are that the agent is trying to satisfy, and the actions

02:34.300 --> 02:35.110
that it has now.

02:35.110 --> 02:40.420
It's not currently printing out the plan, but there's no reason why you couldn't do that.

02:40.420 --> 02:47.680
And if you have a look at the script, then it will give you a pretty decent idea of how you grab the

02:47.680 --> 02:51.580
data from your agent and actually put it into this little area.

02:51.580 --> 02:58.960
But I just created this to help me to make sure that I can see everything and that we can also see very

02:58.960 --> 03:06.970
quickly the pre conditions and the effects and to make sure that things are spelt correctly and that

03:06.970 --> 03:11.890
things are going to all line up when we start to press play.

03:12.520 --> 03:18.160
Now it's time to program the nurse and this is where things start to get interesting.

03:18.190 --> 03:25.960
The nurse can't go into action to get a patient until there's a patient waiting.

03:26.380 --> 03:34.870
So first of all, let's create our nurse script just like we have our patient script, and then we'll

03:34.870 --> 03:36.340
work on it from there.

03:36.340 --> 03:41.590
So let's just grab the patient script and control D to make a copy of it.

03:41.620 --> 03:47.890
Then we will call it nurse and open it up.

03:48.160 --> 03:51.430
Change it from patient to nurse.

03:52.900 --> 03:58.990
So the nurse is going to run the base start, as did the patient.

03:58.990 --> 04:05.860
But the goal in this case will be not is waiting, but treat patient.

04:07.660 --> 04:09.340
And then we add the goal.

04:09.340 --> 04:11.980
So we'll just leave one goal in there at the moment.

04:11.980 --> 04:13.050
So save that.

04:13.060 --> 04:20.560
Let's go back into unity and we will attach that to our solo nurse that we currently have.

04:20.560 --> 04:24.160
So grab that and put it onto the nurse.

04:24.160 --> 04:29.680
Now the nurse's action to get patient will be the first one that we write.

04:29.680 --> 04:35.590
So let's just grab hold of one of the patient ones, like go to hospital and copy it.

04:35.590 --> 04:36.160
Control.

04:36.160 --> 04:40.060
DX And I'm going to call it Get Patient.

04:42.090 --> 04:45.660
Then open that up and rename the class.

04:46.690 --> 04:47.950
To get.

04:49.590 --> 04:50.730
Patient.

04:52.430 --> 04:54.110
And then we'll save it.

04:54.800 --> 04:58.940
Go back to Unity and attach that to our nurse.

04:58.940 --> 05:02.420
So get patient is just there.

05:02.450 --> 05:08.300
Now the action name will be get patient so we can name that there get patient.

05:09.350 --> 05:13.250
And our after effects for now will be.

05:14.580 --> 05:15.840
The goal that we just added.

05:15.840 --> 05:19.140
So we're going to add one and we will call it Treat.

05:19.820 --> 05:23.990
Patient is going to be our after effect.

05:25.220 --> 05:28.940
Okay, now we need a precondition.

05:29.300 --> 05:33.980
So what is the precondition that we're going to set?

05:34.280 --> 05:35.000
Well.

05:36.510 --> 05:39.500
The nurse hasn't done anything to trigger this.

05:39.510 --> 05:46.350
We actually need the world to trigger it or we need something to change in the world that's going to

05:46.350 --> 05:47.040
trigger it.

05:47.370 --> 05:54.840
So in these pre-conditions, what I'm going to do in here is just add one, and the precondition in

05:54.840 --> 06:00.750
this case is going to be waiting or patient waiting.

06:01.110 --> 06:03.780
So we've got this waiting.

06:04.050 --> 06:07.020
Where is waiting going to come from?

06:07.020 --> 06:11.370
So who's goal or who state is that going to be?

06:11.370 --> 06:20.250
It's going to be the world's state and it has to be triggered by the patient when the patient starts

06:20.250 --> 06:21.360
waiting.

06:22.020 --> 06:31.170
So what we need to do is go into our patients waiting code and in the post perform.

06:31.260 --> 06:34.590
What we're going to do here is add in a world state.

06:34.590 --> 06:36.150
So g world.

06:37.330 --> 06:41.320
Dot instance, dot get world.

06:43.180 --> 06:44.860
Dot modify.

06:44.890 --> 06:47.800
State waiting.

06:49.420 --> 06:50.140
One.

06:50.140 --> 06:54.190
So it's going to add one patient that will be waiting.

06:55.000 --> 07:02.290
So now that the patient is going to inject this waiting state into the world, we're going to go back

07:02.290 --> 07:03.580
and start monitoring it.

07:03.580 --> 07:09.490
And that's where this canvas item that's been disabled sitting here causing you a few warnings throughout

07:09.490 --> 07:10.300
comes into play.

07:10.300 --> 07:12.700
So just turn that canvas back on.

07:12.700 --> 07:15.970
You'll see that there's a text box called World Status.

07:15.970 --> 07:22.540
And this is just to display what the world states are and purely just for you to see.

07:22.540 --> 07:25.330
And then when you're not using it anymore, you can just turn it off.

07:25.330 --> 07:31.870
But we need to update the world states to what's in the Dictionary of World States.

07:31.870 --> 07:36.160
And that means writing this script that's missing down the bottom.

07:36.160 --> 07:43.750
So let's go and right click in here and we'll create a new script called Update World.

07:45.140 --> 07:48.920
I open that up and it's going to be very short.

07:48.920 --> 07:53.300
First thing it's going to do is be given the text.

07:53.300 --> 07:56.780
So public text states.

07:58.060 --> 08:03.820
And then in the late update, we'll do this because we don't want to do it very often.

08:04.120 --> 08:05.920
Get rid of the start.

08:06.250 --> 08:16.510
And then we want a dictionary which is of course our string int and world states.

08:18.080 --> 08:26.940
Equals G world dot instance, dot get world dot get states.

08:26.960 --> 08:32.300
Now you could just use this directly in the next for each statement that we're going to create, but

08:32.300 --> 08:37.470
I've just done it there to make the code just a little bit shorter and then we'll just put states dot

08:37.520 --> 08:38.540
text.

08:40.720 --> 08:43.510
Equals empty.

08:44.320 --> 08:48.040
Just get rid of that text.

08:48.730 --> 09:01.810
And then down in here, we want for each key value pair, which will be a string and an int s in world

09:01.810 --> 09:02.980
states.

09:04.090 --> 09:12.100
And then we will just put states dot text plus equals s key.

09:12.100 --> 09:21.850
So that's our string plus a comma space plus a value in case you're actually using that value.

09:21.850 --> 09:26.500
And because we're modifying it, it will update as we're adding patients.

09:26.500 --> 09:31.090
So it's going to go waiting one waiting to waiting through and actually tell you how many are waiting

09:31.690 --> 09:32.620
and.

09:33.780 --> 09:39.810
And put a new line in there now in order to access this text that doesn't seem to like.

09:39.840 --> 09:48.750
Don't forget right at the top we're going to need using unity engine dot UI in order to pick that text

09:48.750 --> 09:52.020
up and those errors should then go away.

09:52.200 --> 09:55.530
If we redefine that as a text.

09:56.610 --> 09:57.440
Okay, good.

09:57.450 --> 09:58.690
So save that.

09:58.710 --> 10:00.510
Let's go back into unity.

10:00.510 --> 10:06.630
And what we're going to do is click on our world states, object in the hierarchy and just put that

10:06.630 --> 10:09.930
missing script back into where it was.

10:10.110 --> 10:16.320
And the text component, which is up here, you can just drag and drop that down into the states case.

10:16.320 --> 10:20.160
So it's this one that's on the same object into states.

10:20.520 --> 10:29.130
And now when we run it, we're going to see that when our patient comes in and goes to the waiting room,

10:29.130 --> 10:34.470
then we will get waiting, appearing up here with a number.

10:34.920 --> 10:38.370
So let's just wait till one of these guys gets in there.

10:45.160 --> 10:45.450
Okay.

10:45.460 --> 10:46.260
Here we go.

10:46.270 --> 10:47.690
He's in there he is now.

10:47.710 --> 10:50.680
Waiting and waiting is one, two.

10:50.680 --> 10:58.060
And as they bunch up and remember, they actually do have to hit the right spot in order to be classified

10:58.060 --> 10:59.050
as waiting.

10:59.050 --> 11:01.180
But it is eventually growing.

11:01.180 --> 11:08.860
So now it's this particular state here that we want to affect the nurse and inject back into the nurses,

11:08.860 --> 11:11.230
get patient action.

11:12.160 --> 11:14.650
Now, that is, in fact, happening.

11:14.650 --> 11:17.470
But why is the nurse moving?

11:17.740 --> 11:21.370
Well, we haven't set the nurses target.

11:21.820 --> 11:26.500
The target needs to be the patient that the nurse needs to pick up.

11:26.500 --> 11:34.150
But just to test that the nurse is actually running this get patient.

11:34.150 --> 11:42.880
Let's just for now give the target to the nurse of that waiting area so she'll be moving towards there.

11:43.750 --> 11:49.120
But it's not the right way to go because we want her to find her actual patient.

11:49.120 --> 11:57.550
So let's just test this again and we'll press play now while we're waiting for these guys to come in.

11:57.550 --> 12:04.660
I hope I'm not being too gender biased or sexist or whatever you might call it by calling the nurse

12:04.690 --> 12:10.630
a she and the patient are he, but to me they kind of look like that, so I'm just going to go with

12:10.630 --> 12:10.990
it.

12:11.530 --> 12:12.700
Okay, so here we go.

12:12.730 --> 12:14.800
Here comes our patient.

12:14.800 --> 12:16.750
He's in there, should trigger the nurse.

12:16.750 --> 12:23.500
And there goes the nurse into action, running that particular get patient.

12:23.890 --> 12:26.470
Now, she's not going to do anything else because that's it.

12:26.470 --> 12:28.450
That was the only thing she knows how to do.

12:28.450 --> 12:33.010
But she's only going into that waiting area, not getting the patient.

12:33.370 --> 12:37.300
And so we'll add that functionality when we come back in the next lecture.
