We're going to begin this video with a challenge.
What I would like you to do is to add a new goal to the patient so that the patient goes home after
he spent his treatment time in the cubicle.
Now, home, if you remember, right back to the beginning, is actually a location in the map.
So there's an item called home here.
It has a home tag.
And if we click on it and just zoom out and have a bit of a look where that home is, you can see that
it's a position over here.
Okay.
So that will just get the agent to walk out of the hospital as though he's going home.
So currently, when our patient gets to the cubicle with the nurse, if we just have a look at our patient
code and come down to our get treatment, this is the last stage.
So it's going to stay there and not go anywhere.
Now, there's no duration set up currently for our get treated.
So if you do want to give that say like a five second duration, so it does take a bit of time for the
treatment to occur.
Then you want to figure out how to get him to leave and go home.
So this is the challenge for you.
Pause the video now.
Give it a go.
When we come back, I'll step through that with you.
Okay.
So how did you go with that?
Well, the first thing you need to do is actually create another action.
So we want to pick a script to duplicate.
That's quite simple.
Go to hospital.
There's not really much going on in there.
Let's duplicate that.
We're going to call it Go Home.
And then you want to open that up and also change the name of the class to go home.
Now, there's really nothing you have to do in this script.
There's no pre perform and there's no post reform.
Everything gets set in the inspector and in fact you probably could just use the same script as go to
hospital and attach that again and just rename the variables in it.
But in this case we've got something separate, so let's just save that.
Now, while we're here, let's go into the patient.
The patient needs to have another goal that is to go home.
Of course, you could have go home after is treated as well.
You could do it that way.
But in this case, I'm just doing it with an extra sub goal.
Okay, so what are we going to do under here is copy this one.
Put it down here.
I call this three.
And in here we will have is home as the goal.
Okay, so save that.
Now let's go back in to Unity and select our patient.
So we're going to go home on to the patient there and let's name it as go home.
The target tag in this case is home and there's no duration, the pre condition.
We're going to add in a precondition one here.
And we don't want the patient to actually go home until they're cured.
So I put is cured here as the pre condition the after effect which has to match the goal.
We want one of those and it's going to be is home.
Okay.
So where do we put is cured?
Well, it's not going to be a world state because it has to apply to the actual patient.
That means that whatever action is happening to cure the patient will need to inject that belief into
the patient so the patient is getting cured in its get treated script.
So if we go into get treated.
You can see that I've already added this in here and all you've got to do is just add beliefs, dot
modify state.
Is cured and that will go into the agents beliefs and then allow that extra task or action to execute.
Now let's go back into Unity to play it.
Actually, before I do, let's just go into G World.
And I just wanted to show you a little bit of code that I've put in here to make things run a hell of
a lot faster so you could speed up the agents movement, but that's going to give you inaccurate sort
of, I guess, movement and physics on the nav mesh.
Instead, you just want to speed the entire simulation up.
So you can do that by changing the time scale somewhere within your code that runs like first up.
That's why I've got it inside of the instantiate for the G world and set it to five.
So it's going to do five times of speed.
Okay, so save that.
Now, with all of that done, we can now check out our full plan for our patient.
All right.
So if you've been using the patient like I have and turning it on and off and then make sure you also
override it while it is turned on and then you can turn it off.
I'm going to leave this guy on now.
I've just moved him outside so he can be the first guy that comes in.
Let's have a look at how this runs and what does the nurse do when the patient goes home.
So let's have a look.
They coming in, the nurse gets the patient, go over to the cubicle, he goes home.
She's like thinking about picking up someone else, which she does.
She goes and gets him because that's her goal.
That's what she does.
She just wants to treat a patient.
As long as there's a patient available, she's just going to keep running that goal over and over again.
And as you can see, she's doing a great job of it.
Okay.
So she's getting a bit overwhelmed.
This has been a introduction to goal orientated action planning and I'm sure by now you can see the
power that is in it.
If you're very interested in continuing on and learning more about this system and building a more interactive
hospital like the one you can see here on the screen, then please do visit my learning website where
you can interact with other students who are also building the same simulation.