WEBVTT

00:06.550 --> 00:12.490
Now that we've created one action, we're going to string two actions together.

00:12.790 --> 00:19.060
So before I just do that, I'll just mention a warning that you could be getting in the console when

00:19.060 --> 00:22.780
you press play, press play so we can get that warning to come up.

00:22.780 --> 00:28.660
And it's about world states and UN referenced behaviors and missing things.

00:28.660 --> 00:34.180
Just ignore that it's being generated by the canvas in the world.

00:34.180 --> 00:41.560
And even if you if we stop playing for a second, turn that canvas off and press play, you still get

00:41.560 --> 00:43.630
the same error coming through or warning.

00:43.630 --> 00:47.560
It's not going to affect anything at the moment and we'll fix it later.

00:48.730 --> 00:55.600
Another thing I'll get you to modify before you start creating more complex plans is the late update

00:55.600 --> 00:58.440
in your G agent code.

00:58.450 --> 01:08.590
So we were testing previously for the agent having a path and then also using the agents remaining distance

01:08.590 --> 01:13.540
to the object that is going to and you might have a different value from 0.5 in here.

01:13.990 --> 01:20.200
But the thing is, once you start moving your agent between different markers, the accuracy of that

01:20.200 --> 01:21.490
seems to break down.

01:21.490 --> 01:28.780
Or if it jumps to another waypoint before it's finished the path and that you can get some skipping

01:28.780 --> 01:35.020
out of your agents where they will look like they're going to go and complete that entire plan.

01:35.020 --> 01:41.080
But they actually just skip on and go home because of the issue with that nav mesh accuracy.

01:41.080 --> 01:46.960
So instead, inside of this late update for G agent, I'd like you to to change your if statement.

01:46.960 --> 01:54.910
That's the first part inside of here and we will actually calculate our own distance to target between

01:54.910 --> 02:00.100
the current actions target and the position of the agent.

02:00.100 --> 02:07.630
And then we'll use that as a comparison inside of this if statement instead of the old code here.

02:07.630 --> 02:14.740
And that should and will, I promise you, stop your agents from skipping out on the plans a little

02:14.740 --> 02:15.610
later down the track.

02:15.610 --> 02:20.680
And if you want to see the difference, then when you do get multiple stepped plans that the agent has

02:20.680 --> 02:26.500
to go through, you can always come back and put this code in to see the difference in the behavior.

02:27.160 --> 02:27.520
Okay.

02:27.520 --> 02:35.380
So let's now add in another action that we can basically hook up to go to hospital.

02:35.380 --> 02:39.970
So currently all we've done with go to hospital is have the agent go into the waiting room.

02:39.970 --> 02:48.250
Let's now make go to hospital where the agent has to go to the front door and then go in the waiting

02:48.250 --> 02:48.790
room.

02:49.270 --> 02:52.240
So that's going to make go to hospital to begin with.

02:52.270 --> 02:57.670
We click on the patient to find we've hooked that up the script itself.

02:57.670 --> 03:01.690
So the action name we should probably change that to go to.

03:02.610 --> 03:09.180
Hospital because you'll be able to see this plan in the console when it's worked out.

03:09.210 --> 03:12.690
Now, the waiting area itself is the target, but go to hospital.

03:12.750 --> 03:14.850
You want to just set it to the main door now?

03:14.850 --> 03:15.660
The door.

03:15.690 --> 03:19.290
Remember, I've got this empty game object.

03:19.290 --> 03:26.430
Essentially, that's just a position in front of the door and we can see it in the same view sitting

03:26.430 --> 03:27.000
just there.

03:27.000 --> 03:30.050
So that's the spot we want to get our agent to go to.

03:30.070 --> 03:33.090
Now the door is tagged with door.

03:33.180 --> 03:36.810
Instead of assigning the game object of door to our patient.

03:36.810 --> 03:39.090
This time what we're going to do is use the tag.

03:39.090 --> 03:41.970
So let's just null out what's in there.

03:41.970 --> 03:45.570
And I think if we just hit delete on it, it will make it empty.

03:45.570 --> 03:51.480
And then in here it type door, which is our tag for the door, make sure it's got a capital D so that

03:51.480 --> 03:57.870
once this patient becomes a prefab a little bit down the track, it's going to find the door when it's

03:57.870 --> 04:03.390
instantiated rather than the game object itself using the game object.

04:03.690 --> 04:04.860
Okay, now the duration.

04:04.860 --> 04:10.440
You can see that I've changed to five in the doorway, so you'll see him pause when he gets into the

04:10.440 --> 04:13.020
doorway and 5 seconds is probably a little bit too long.

04:13.020 --> 04:17.640
Let's put it down to two and the after effect.

04:17.640 --> 04:22.110
Now I've got it as is waiting, but it will be something else.

04:22.110 --> 04:25.230
So let's change it to has arrived.

04:26.350 --> 04:34.300
Now after has arrived, we want him to go into the waiting room so we need another action that will

04:34.300 --> 04:37.030
link up to has arrived.

04:37.030 --> 04:46.780
So grab your go to hospital script, duplicate it, control D and then what I want you to do is rename

04:46.780 --> 04:50.830
that to go to waiting room.

04:52.090 --> 04:58.960
And then we're going to open that up in the editor and change the class name to go to waiting room as

04:58.960 --> 04:59.560
well.

05:03.740 --> 05:07.550
So up here it will be go to.

05:09.960 --> 05:12.420
Waiting room.

05:13.500 --> 05:16.840
And we're just going to save that switch back into unity.

05:16.860 --> 05:21.870
Now get go to waiting room and drag and drop it onto your patient.

05:23.980 --> 05:34.660
The action name will set to go to waiting room and the target tag will be a waiting area.

05:34.660 --> 05:37.030
So let's just see what that is tagged as.

05:37.120 --> 05:41.500
It's waiting area with no spaces in it and two capital.

05:41.500 --> 05:44.710
So waiting area.

05:45.710 --> 05:51.770
Out pre-condition this time there's going to be one of them and it's going to be has arrived, which

05:51.770 --> 05:55.940
is up here in the go to hospital as the after effect.

05:55.940 --> 06:00.260
And that's what's going to link these two actions together.

06:00.260 --> 06:02.570
So has arrived.

06:03.980 --> 06:10.040
And then the actual effect of go to waiting room has to be our goal.

06:10.040 --> 06:12.650
Otherwise the agent will not run this.

06:12.650 --> 06:14.720
And our goal is is waiting.

06:15.020 --> 06:21.650
And if you remember in our agent code, that's the actual goal that is being run.

06:21.650 --> 06:25.700
Now, the duration for the waiting room is zero at the moment.

06:26.360 --> 06:29.780
That's kind of the end of our action plan.

06:29.780 --> 06:32.810
So there's no need for a real duration.

06:33.380 --> 06:35.300
Okay, so we've got that now.

06:35.300 --> 06:36.770
We're ready to press play.

06:37.010 --> 06:43.940
So press play and our patient should head over to the door.

06:43.940 --> 06:49.940
And then when he gets to the door, he's going to wait for 2 seconds because that's the duration of

06:49.940 --> 06:51.470
the task of arriving.

06:51.710 --> 06:55.790
And then he's going to turn around and go into.

06:56.770 --> 06:58.120
The waiting room.

07:00.040 --> 07:00.880
Okay.

07:00.910 --> 07:01.270
Great.

07:01.270 --> 07:04.090
So that's linking up to.

07:04.840 --> 07:05.860
Actions.

07:06.490 --> 07:08.980
Now I'm going to set you a challenge.

07:09.010 --> 07:18.280
What I'd like you to do is to create a third action and put it in between, go to hospital and go to

07:18.280 --> 07:19.060
waiting.

07:19.060 --> 07:22.660
And this action will be called register.

07:23.170 --> 07:31.480
So I want your agent to go to the front door, then to go to the reception desk and wait there for 5

07:31.480 --> 07:35.530
seconds and then go into the waiting room.

07:35.740 --> 07:43.360
So pause the video now and golf and add that action in and make sure you attach it to the patient and

07:43.360 --> 07:48.740
you've got all the right pre and post conditions all set up for it.

07:48.760 --> 07:53.080
And when we come back, I'll go through how to put that together.

07:54.300 --> 07:54.800
Okay.

07:54.810 --> 07:56.370
How did you go with that?

07:56.400 --> 08:01.940
First of all, what I'm going to do is just create another folder in here and I'm going to call it go

08:01.940 --> 08:06.270
up and move all of these base classes in there.

08:06.270 --> 08:12.300
Because as you start creating more and more actions, the whole thing is going to get very populated

08:12.300 --> 08:17.410
with scripts and trying to find them will get annoying.

08:17.440 --> 08:19.830
Okay, so these are the high levels that we've got.

08:19.920 --> 08:23.700
We've got the patient and go to hospital and go to waiting room.

08:23.700 --> 08:27.540
Now we need another one of these which is going to be register.

08:27.540 --> 08:30.990
So I'll just duplicate it and I'll call it register.

08:33.120 --> 08:35.130
And then open that up.

08:35.760 --> 08:39.090
And in here, just rename it to register.

08:41.460 --> 08:42.240
Save it.

08:42.600 --> 08:51.210
Now let's go back into here or select our patient and we're going to drag and drop register onto the

08:51.210 --> 08:52.050
patient.

08:52.080 --> 08:55.570
Let's first of all, call it register.

08:55.680 --> 08:58.590
Give it a name for its action is register.

08:59.160 --> 09:00.990
And the duration.

09:00.990 --> 09:03.480
I said 5 seconds.

09:03.480 --> 09:11.070
Now, the target tag in this case is going to be our reception desk and just click on it and it's tag

09:11.070 --> 09:12.240
is reception.

09:12.330 --> 09:16.230
So let's go back and put reception in there.

09:18.000 --> 09:25.860
The preconditions are going to be the post conditions or the effects of go to hospital.

09:25.860 --> 09:33.780
So we want to put a one in there for the size and then inside of here we want has arrived.

09:34.200 --> 09:36.060
So let's put has arrived.

09:38.440 --> 09:41.410
And then the after effects.

09:41.410 --> 09:44.440
We're going to put one in here and put.

09:46.300 --> 09:47.170
Has.

09:48.830 --> 09:49.940
Registered.

09:51.480 --> 09:57.030
Now that has registered will become the precondition for going to the waiting room.

09:57.030 --> 10:04.740
So up in the go to waiting room for your precondition change that now to has registered.

10:07.050 --> 10:07.340
Okay.

10:07.500 --> 10:10.380
And now they should all link.

10:10.380 --> 10:17.850
Your goal is still the same, but your agent is now going to, well, you know, go through these three

10:17.850 --> 10:19.320
steps, right?

10:19.320 --> 10:23.040
So let's press play and just check what the agent does.

10:23.250 --> 10:29.850
He is going to go over to the main door, which is essentially simulating him coming in to the hospital.

10:29.850 --> 10:35.040
I know he's already in the hospital, but he would be outside the hospital 2 seconds there.

10:35.040 --> 10:41.280
He's going to come and register, which takes 5 seconds, and then he's going to go and wait in the

10:41.280 --> 10:42.330
waiting room.

10:47.430 --> 10:48.050
Okay.

10:48.060 --> 10:48.710
Nice.

10:48.720 --> 10:49.140
Right.

10:49.140 --> 10:54.750
So now that we've done that, you might want to spawn some more patience.

10:55.350 --> 11:03.630
And I'm going to leave the challenge of creating a simple spawn for these patients up to you for the

11:03.630 --> 11:04.710
end of this video.

11:04.710 --> 11:08.220
We'll come back in the next video and continue working on this.

11:08.220 --> 11:15.540
So just make sure that your spawn for your patients is also outside the hospital so they have to come

11:15.540 --> 11:17.850
in from the outside.

11:17.850 --> 11:19.890
And I'll see you in the next video.
