Now that we've created one action, we're going to string two actions together.
So before I just do that, I'll just mention a warning that you could be getting in the console when
you press play, press play so we can get that warning to come up.
And it's about world states and UN referenced behaviors and missing things.
Just ignore that it's being generated by the canvas in the world.
And even if you if we stop playing for a second, turn that canvas off and press play, you still get
the same error coming through or warning.
It's not going to affect anything at the moment and we'll fix it later.
Another thing I'll get you to modify before you start creating more complex plans is the late update
in your G agent code.
So we were testing previously for the agent having a path and then also using the agents remaining distance
to the object that is going to and you might have a different value from 0.5 in here.
But the thing is, once you start moving your agent between different markers, the accuracy of that
seems to break down.
Or if it jumps to another waypoint before it's finished the path and that you can get some skipping
out of your agents where they will look like they're going to go and complete that entire plan.
But they actually just skip on and go home because of the issue with that nav mesh accuracy.
So instead, inside of this late update for G agent, I'd like you to to change your if statement.
That's the first part inside of here and we will actually calculate our own distance to target between
the current actions target and the position of the agent.
And then we'll use that as a comparison inside of this if statement instead of the old code here.
And that should and will, I promise you, stop your agents from skipping out on the plans a little
later down the track.
And if you want to see the difference, then when you do get multiple stepped plans that the agent has
to go through, you can always come back and put this code in to see the difference in the behavior.
Okay.
So let's now add in another action that we can basically hook up to go to hospital.
So currently all we've done with go to hospital is have the agent go into the waiting room.
Let's now make go to hospital where the agent has to go to the front door and then go in the waiting
room.
So that's going to make go to hospital to begin with.
We click on the patient to find we've hooked that up the script itself.
So the action name we should probably change that to go to.
Hospital because you'll be able to see this plan in the console when it's worked out.
Now, the waiting area itself is the target, but go to hospital.
You want to just set it to the main door now?
The door.
Remember, I've got this empty game object.
Essentially, that's just a position in front of the door and we can see it in the same view sitting
just there.
So that's the spot we want to get our agent to go to.
Now the door is tagged with door.
Instead of assigning the game object of door to our patient.
This time what we're going to do is use the tag.
So let's just null out what's in there.
And I think if we just hit delete on it, it will make it empty.
And then in here it type door, which is our tag for the door, make sure it's got a capital D so that
once this patient becomes a prefab a little bit down the track, it's going to find the door when it's
instantiated rather than the game object itself using the game object.
Okay, now the duration.
You can see that I've changed to five in the doorway, so you'll see him pause when he gets into the
doorway and 5 seconds is probably a little bit too long.
Let's put it down to two and the after effect.
Now I've got it as is waiting, but it will be something else.
So let's change it to has arrived.
Now after has arrived, we want him to go into the waiting room so we need another action that will
link up to has arrived.
So grab your go to hospital script, duplicate it, control D and then what I want you to do is rename
that to go to waiting room.
And then we're going to open that up in the editor and change the class name to go to waiting room as
well.
So up here it will be go to.
Waiting room.
And we're just going to save that switch back into unity.
Now get go to waiting room and drag and drop it onto your patient.
The action name will set to go to waiting room and the target tag will be a waiting area.
So let's just see what that is tagged as.
It's waiting area with no spaces in it and two capital.
So waiting area.
Out pre-condition this time there's going to be one of them and it's going to be has arrived, which
is up here in the go to hospital as the after effect.
And that's what's going to link these two actions together.
So has arrived.
And then the actual effect of go to waiting room has to be our goal.
Otherwise the agent will not run this.
And our goal is is waiting.
And if you remember in our agent code, that's the actual goal that is being run.
Now, the duration for the waiting room is zero at the moment.
That's kind of the end of our action plan.
So there's no need for a real duration.
Okay, so we've got that now.
We're ready to press play.
So press play and our patient should head over to the door.
And then when he gets to the door, he's going to wait for 2 seconds because that's the duration of
the task of arriving.
And then he's going to turn around and go into.
The waiting room.
Okay.
Great.
So that's linking up to.
Actions.
Now I'm going to set you a challenge.
What I'd like you to do is to create a third action and put it in between, go to hospital and go to
waiting.
And this action will be called register.
So I want your agent to go to the front door, then to go to the reception desk and wait there for 5
seconds and then go into the waiting room.
So pause the video now and golf and add that action in and make sure you attach it to the patient and
you've got all the right pre and post conditions all set up for it.
And when we come back, I'll go through how to put that together.
Okay.
How did you go with that?
First of all, what I'm going to do is just create another folder in here and I'm going to call it go
up and move all of these base classes in there.
Because as you start creating more and more actions, the whole thing is going to get very populated
with scripts and trying to find them will get annoying.
Okay, so these are the high levels that we've got.
We've got the patient and go to hospital and go to waiting room.
Now we need another one of these which is going to be register.
So I'll just duplicate it and I'll call it register.
And then open that up.
And in here, just rename it to register.
Save it.
Now let's go back into here or select our patient and we're going to drag and drop register onto the
patient.
Let's first of all, call it register.
Give it a name for its action is register.
And the duration.
I said 5 seconds.
Now, the target tag in this case is going to be our reception desk and just click on it and it's tag
is reception.
So let's go back and put reception in there.
The preconditions are going to be the post conditions or the effects of go to hospital.
So we want to put a one in there for the size and then inside of here we want has arrived.
So let's put has arrived.
And then the after effects.
We're going to put one in here and put.
Has.
Registered.
Now that has registered will become the precondition for going to the waiting room.
So up in the go to waiting room for your precondition change that now to has registered.
Okay.
And now they should all link.
Your goal is still the same, but your agent is now going to, well, you know, go through these three
steps, right?
So let's press play and just check what the agent does.
He is going to go over to the main door, which is essentially simulating him coming in to the hospital.
I know he's already in the hospital, but he would be outside the hospital 2 seconds there.
He's going to come and register, which takes 5 seconds, and then he's going to go and wait in the
waiting room.
Okay.
Nice.
Right.
So now that we've done that, you might want to spawn some more patience.
And I'm going to leave the challenge of creating a simple spawn for these patients up to you for the
end of this video.
We'll come back in the next video and continue working on this.
So just make sure that your spawn for your patients is also outside the hospital so they have to come
in from the outside.
And I'll see you in the next video.