Welcome back my fellow game developers to honestly,
one of the best videos that I have ever made
because this is one of
the few times that something happens.
We have a bug in the game,
but it actually turns out to be much
better than what was originally intended.
So it's amazing.
You'll see what I mean during the video.
But for now, let's run the game.
And you'll see that I've created this little goblin.
So this Goblin just walks around randomly.
So you can see he walks through some point,
he stops, he then walks away.
He stops.
And if we get close enough,
you can see that he starts chasing and
throwing bombs that are throwing bombs on us.
Look, how cool is that if we
get away from him, There we go.
You can see that he just continues to walk
around until we get back and range.
And then he starts chasing us
like a freaking lunatic was that night.
I seriously, I'm so lucky to have form these bright.
They are so cool. So let's not waste
any more time and let's get started.
Oh, okay, So now we have a cowardly enemy.
Time to add the wonderful.
So I'm going to go into my enemies and the prefabs.
And in here I'm going to add
the patrolling, nope, the covalent.
There we go. So we add the goblin.
Let's remove the card or you know what?
Let's turn off the currently fly.
Maybe we'll add them later on.
And then we are going to check out the goblins.
So look at the government.
How cool is he?
So he runs around, he shoots people.
I don't know with what I know what he does.
Actually, he just I think he throws a bomb or something.
But anyways, he is going to be a wonderful.
So let's go and he's called the goblin wonder one.
So let's make him the goblin wonder, apply the changes.
Okay, so the name is still the same.
Anyways, let's open up our scripts
and let's see what we are going to do in here.
So I'm going to go up and in here I'm going to create
the enemies that wonder and Chase.
Or let's just call it the enemies that wonder.
So in here I'm going to create a serialized field.
And it's going to be a Boolean.
And it's going to be, should wonder, wonder,
wonder, is it a, was it,
Oh, no, I'm just going to stick with a.
So wonder, wonder.
And then I'm going to create
a serialized field for two floats.
The first one is going to be the Wonder length.
So how long does he wonder?
Wonder. I'm going to say it however I want.
And then we have the pulse length.
So for how long does he
paused before he starts wandering again?
And then I'm going to create
obviously two things because it
seems that it's obvious
that we are using counters in here.
So I'm going to create
a private float and wander counter.
And then the false counter.
By the way, something that I believe I did not
mentioned in the previous video and the game mode.
I've turned off everything related to music,
so I've made sure that the music audio is
off just for testing reasons.
We don't want to keep having background music
and four for my neighbors obviously
to keep them sane in the next couple of months until I
finished recording and new ways back in here.
I don't need the cops again anyways private.
And finally, we need to
obviously get the wonder direction.
In here we are going to get the direction to move
in and it's going to be the Wonder direction.
We still have inserted, but we will.
And then we're going to check.
And then as we are removing from the Wonder counter,
we are going to check if at any point
the wonder counter becomes less than or equal to 0.
We are then going to set
something called the pause counter.
And this pause counter isn't
just going to be any post counter.
We are going to create a random dot range.
And this random.randrange will have the pos
counter times 0.75 F,
and the counter times 1.25.
So you might be wondering,
why are we doing this?
Well, because we want to have
a very random way of posing our gain,
or sorry, not passing our game of pausing the enemy.
So he will wait a really different
time every single time before he starts moving.
This will add more variety to the way he moves.
And then after we check in here,
so we check for the wonder counter would remove from it.
We set the direction.
Now it's actually time to
decide which direction we are going to be going in.
So in here I'm going to check if
the boss counter is still greater than 0.
The pos counter is greater than 0.
Obviously, the first thing we're going to do is we'll be
removing from the post counter,
so time dot delta time.
And then we are going to check if
the pulse counter at any point
becomes less than or equal to 0.
Then in here we are going to do two things.
The first thing is we are going
to choose the past counter.
And instead we are going to be
setting the wonder counter.
And it's going to be the OK, sorry,
it's not the pause counter,
It's the pause length.
So pause length.
Pause length, sorry for that.
And in here instead of the pos counter,
we're going to set the wonder length.
And the wonder length.
So this was a, something I did
not know this, excuse me for that.
But in here we don't just want to set the counter,
we also want to set the wonder direction.
And this is going to be your challenge.
Your challenge is to give the wanderer a random,
not end a random.
So after we reset the counter,
we need a new wonder direction.
You'll need to set the wonder direction
as a new vector 3.
You will need to set the x and
the y should be random numbers.
Make sure that you keep the z as it is or even better,
you should sell it as 0.
Finally, a hint as to make the range between minus 1.551.
And that's just saw that the enemy
doesn't wander very far along.
So for that information,
pause the video right now and go do the Chaldean.
Okay, welcome back.
How did you get on with that?
So after we set the wonder counter,
we are going to set the wonder direction.
And the wonder direction obviously
as a factor three, you can see it right here.
So we're going to create
a new vector 3 and we're going to open up.
Now, obviously the zed axis should stay the same.
So we're going to set a random dot range and it's
going to be minus1, f minus 1.551.
Then we are going to set this one for the x,
this one as for the y.
And finally, we have zeros at the end.
So let's look back at what is happening in here.
First of all, we start off,
we check, should we wonder if yes,
then we're going to check as
the wonder counter greater than 0,
then we continue on which we keep removing time from it.
We set the direction because obviously we are wondering,
we just want to set the direction immediately.
And then we keep removing,
doing this loop, doing this loop, doing this loop.
Obviously at this point the pos counter should be 0.
But when the wonder counter is less than 0,
the past counter gets a random value.
And then we get this condition to true,
and this one will be at false.
So we start off right here,
start removing from the pos counter until at 1,
we get a pos counter that it's less than 0.
We set a random wonder counter,
and at the same time we set a wonder direction.
We stopped this if statement.
We go back in here and again we start removing.
We have a new wonder direction that we've
determined right here during the past-time.
And we keep removing until again,
the wonder counter is less than 0,
a new post counter.
We start this one and we continue on doing all of that.
But there is one thing
that you need to consider and that is
we need to initiate
either the boss counter or the wonder counter.
So up and start.
I'm going to create a condition in here.
And if we should wonder,
I remember that was the condition.
Should wonder.
If we should wander,
then we need to set a pos counter,
which is equal to a random dot range between
the boss length times
0.75 and then the boss length times 1.25.
There we go. So it's pretty
much the same as we have in here.
Up here. We initialize the boss counter.
He waits or the enemy waits a bit.
Then he realizes, oh,
I need to start moving in here,
whereas it in here.
So we initialize some value,
we start from moving from it.
When it gets to less than 0,
we start the whole chain in here and he starts chasing,
I mean, sorry, wandering.
And there's something because we wanted to
add the chasing to the enemy.
First, let's see if this actually
works and then we will add the chasing.
So back in our game.
Let's see what we have in here.
So the goblin wondering,
let's first of all set everything.
So let's keep these should chase away.
And so the blue one is for the projectile.
So I'm going to maybe
make the shooting range a little bit smaller.
And then the time between shots,
Let's keep it as it is.
Should run away. No, should wander.
Yes. Wonder length.
How long does he wandered around? For 1 second.
How long does it pause?
You know what, Let's keep two.
And to save that, run the game.
And let's see how that looks.
So I'm going to get there but close to him. There we go.
You can see that he just went in
some random direction. And there you go.
You can see that every two seconds he just walks around.
There, he stops there.
Let's see.
And then you can see it's not
a very smart enemy obviously.
He sometimes walks and two walls. He gets stuck there.
Okay, so he's running after us.
There you go. He's in range.
Does the shoot, is maturing.
Okay. So oh, there we go.
So he is shooting when he gets arranged.
How cool is that?
Now, the next thing that we want to add
is if we get in the vicinity of this enemy,
we want him to start not just drooling and us,
but actually running towards
us because he has a bomb, it's heavy.
He needs to get close to throw at us.
This is something I just came up with.
So how are we going to do this?
The problem in here is that we are
either we have the condition for the chasing,
all, we have the condition for the wandering.
So if I go back in here and I just said the, where is it?
Where is the little guy right here?
The goblin wonder, so should chase player,
then we are going to have the player chase range.
There we go. So it's a little bit,
maybe it's like that and the keep chasing.
Okay, sure, Let's just make random like this.
Strange. Let's see what happens
when he actually starts chasing us.
And there we go. Let's see how that would work.
So I get close to him.
And as you can see, is each chasing.
Okay, so he is chasing,
then going again and wandering.
So if I stay in here,
you can see that it's kind of a mechanic,
but at the same time he stops somewhere.
And what, I'm actually very surprised,
by the way, his movement is really crazy and amazing.
So you can see that he keeps chasing.
At some point, he just starts wandering again.
So I love the randomness in this, but just,
just for the sake of understanding
how I wanted to make the game
or how my idea of what I wanted to do is he wonders.
But when the player is in the range chasing,
then he starts chasing and stops wondering.
So let's see how that will look.
So back in here,
you can see that when we start chasing,
we said the is chasing to true.
So in here, we should check for two things.
If we should be wondering and where's it?
And we are not chasing,
so he is not chasing.
So back in here,
we run the game and now you'll
notice that he will be wondering.
So we are outside the chase range.
He wanders around, he wanders around,
Hopi goes my way.
So obviously you can see
that random immunity isn't that good.
So you can see that we are in range and there we go.
You can see that he is chasing us.
He is no longer just wondering,
he will keep chasing us until we get a bit away.
And there we go. You can see that
he just keeps wandering around.
Now, honestly, I love how he was just going between
wandering and chasing and his movement was
very erratic and he was not sure what's happening.
I loved it.
If you want, you can keep it that way.
And f naught if you'd like the way he was just pausing,
chasing us and then when we get away,
he just keeps wandering.
Then be my guest is up to you.
And as you can see, sometimes you just come up
with things and little bugs in the game,
make the interesting parts
of the game. I hope you enjoy it.
I hope you are committing your changes.
I hope you have loved a review.
It helped me out a lot.
So if you haven't already, don't hesitate,
bolded may review, it really,
really helps me out a lot.
If not, I'll see you in the next video where we will be
creating the last enemy which is deep patrol or so.
See you then.