WEBVTT

00:13.170 --> 00:18.390
The one the behavior is what you want a character to do when it has no official goal location to go

00:18.390 --> 00:22.440
to, I guess you could consider it as the ideal state of steering.

00:22.960 --> 00:28.650
It has to be random, but not too random to ensure the character isn't jumping around from location

00:28.650 --> 00:30.870
to location in an erratic way.

00:31.320 --> 00:35.580
In this video, we all look at just one way to produce a nice wonder.

00:36.390 --> 00:41.180
It works by using an imaginary circle that is sitting in front of the character.

00:41.640 --> 00:47.880
The circle has a target location positioned on the circumference that moves back and forward around

00:47.880 --> 00:48.480
the circle.

00:48.990 --> 00:54.330
As it moves, the agent has its target updated and it changes directions.

00:55.150 --> 01:01.380
There are three variables that basically define the system and how it causes the agent to behave.

01:02.010 --> 01:07.470
The one the distance, which is the distance from the agent to the middle of the circle, the one to

01:07.470 --> 01:15.060
radius that defines the size of the circle and the one the jitter that influences how the target location

01:15.060 --> 01:17.750
moves around from update to update.

01:18.300 --> 01:21.390
So let's go ahead and program this into the bot.

01:21.810 --> 01:23.540
Open up the code.

01:23.550 --> 01:26.400
Now we're going to add this same place.

01:26.400 --> 01:27.490
We've been adding everything else.

01:27.490 --> 01:29.460
So just void wonder.

01:31.110 --> 01:33.000
And in here.

01:34.330 --> 01:40.540
Or eventually going to use the seek, but first of all, we need to calculate all of the value so we

01:40.540 --> 01:43.540
need a float for wander radius.

01:45.940 --> 01:51.220
And we'll set that 10:00, then we need a float for Wanda Dist..

01:52.640 --> 01:53.930
Set that to 20.

01:54.930 --> 02:01.910
And then we need a float for Wanda Jittered and we will set that to one which is really not very much

02:01.920 --> 02:03.090
jitter at all.

02:03.750 --> 02:09.810
OK, so these values here are the ones that you want to change if you want to change the behavior of

02:09.810 --> 02:15.810
the actual wandering and you could make them public floats at the top of your code so you could access

02:15.810 --> 02:18.300
them through the inspector and change them in there.

02:18.780 --> 02:28.170
Now we need a wand, a target that want to target needs to be updated each time with a new value that

02:28.170 --> 02:33.150
the target position is going to move, which means we need to keep remembering where it was so we can't

02:33.150 --> 02:34.750
put it in a local variable.

02:35.190 --> 02:41.400
I'm just going to put it above my method here so that you can see it rather than going up to the top

02:41.400 --> 02:42.090
of the code.

02:42.570 --> 02:47.640
But if you like to keep everything nice and neat, then you could put it up there.

02:48.570 --> 02:53.670
So I'm going to just make this Vector 3.0 to begin with.

02:55.100 --> 03:01.670
OK, so then what we're going to do after we've done that, we want to put Wanda Target.

03:03.580 --> 03:06.490
Plus equals new Victa three.

03:08.340 --> 03:16.860
And we're going to pick a random value between minus one and one multiplied by a jeta value, and that's

03:16.860 --> 03:19.310
going to allow us to go forward and backwards.

03:19.800 --> 03:26.790
So random dot range between minus one point zero F and 1.0 F.

03:28.170 --> 03:31.380
Multiplied by our Wanda Gita.

03:32.820 --> 03:38.890
That's for our X value, the Y value is going to start at zero because we don't want to affect that.

03:38.910 --> 03:44.500
And then for the Z value common, the random range.

03:44.520 --> 03:53.420
Same thing again, minus one point zero F and one point zero F multiplied by L Wonder Jitter.

03:55.140 --> 03:58.830
And then we just close that off.

03:58.860 --> 04:06.840
OK, so that's going to give us a new target that moves the existing one to target, which is initially

04:06.840 --> 04:13.000
zero now that we want to target actually has to be sitting on the circumference of the circle.

04:13.470 --> 04:20.790
So once you modified here, you're going to end up with a position that is in the direction of the circle,

04:20.790 --> 04:23.360
but not not sitting on the circle anymore.

04:23.370 --> 04:27.170
So we need to do a few things to put it back on the circumference of the circle.

04:27.660 --> 04:30.200
So we're going to, first of all, normalize it.

04:30.210 --> 04:37.890
So we want to target dot normalize, which will bring it down to a length of one, and then we're going

04:37.890 --> 04:38.780
to go one.

04:38.780 --> 04:48.720
The target multiplied equals one to radius to push it out to the right length.

04:49.650 --> 04:56.520
OK, so essentially what we've done here is we've created this one to target, which is sitting on the

04:56.700 --> 05:04.080
circumference of a circle which is currently positioned around the agent, which has a zero zero zero

05:04.410 --> 05:05.160
center.

05:05.580 --> 05:11.160
But our circle, remember, is actually offset by the wonder distance.

05:11.580 --> 05:17.630
So what we need to do with it is to create a position that's in front of our agent.

05:17.640 --> 05:24.750
So let's create a vector three target and we're going to call this local because it's local to the agent,

05:24.750 --> 05:30.660
as though the agent was currently the center of the world, like at zero zero zero in the circle is

05:30.660 --> 05:32.280
sitting around the agent.

05:32.760 --> 05:42.480
So we'll go target locals going to equal the Wanda target plus vector three.

05:44.100 --> 05:52.680
Zero in the Z direction, zero in the water action, and then wander distance in the Z direction because

05:52.680 --> 06:00.000
we're moving it forward from the agent, OK, so we want to distance that moves our local target out,

06:00.390 --> 06:05.870
then we need to make that local target into a world position that we can then seek.

06:06.270 --> 06:15.960
OK, so we just need to convert it to target world, which will equal this game, object, dot, transform

06:15.960 --> 06:21.900
and just what we had the transform vector before to go from WorldSpace into local space.

06:21.910 --> 06:23.210
We're now going to go back the other way.

06:23.220 --> 06:30.570
So inversed transform vector and Target Local.

06:30.580 --> 06:37.260
And now we have a world position which we can say, OK, so put seke target.

06:38.900 --> 06:44.170
World now to get this one to two happened, don't forget to change it in your updates.

06:44.170 --> 06:51.020
So let's just put wonder down in there, OK, let's save this and let's go back into unity.

06:51.140 --> 06:51.560
All right.

06:51.560 --> 06:57.520
So let's press play and have a look at the movement of this guy.

06:58.400 --> 07:00.610
You see a little bit of movement, OK?

07:00.680 --> 07:02.300
Always decided to change direction.

07:02.300 --> 07:09.320
And that's because we've got a negative value in there to allow us to create negative directions and

07:09.320 --> 07:10.660
turn the boat around.

07:11.000 --> 07:17.080
He's not very erratic because our Wanda Gita is down quite small.

07:17.790 --> 07:21.110
OK, so let's just now go back into our code and change that.

07:21.110 --> 07:27.940
So he's a wanted to let's change that to 10 and have a look how that affects our agent.

07:27.950 --> 07:28.820
So save that.

07:28.820 --> 07:30.350
Let's run it again.

07:31.100 --> 07:33.400
OK, so let's find him.

07:36.030 --> 07:44.220
And he's more erratic as far as changing direction and even just from side to side wondering around,

07:44.900 --> 07:45.960
you can say they're.

07:50.820 --> 07:51.330
OK.

07:52.390 --> 07:57.850
That's great, so the other things you can try if we get back into our book code again is increase the

07:57.850 --> 08:01.090
wonder radius, which is going to make that circle bigger.

08:01.120 --> 08:08.770
So if you put that to like 50 and the distance, if you increase the distance from the circle, then

08:09.460 --> 08:14.380
as you move that circle further and further away, then so your target point is getting further and

08:14.380 --> 08:20.170
further away, which means you're going to get with a bit more smoother movement as you do this.

08:20.180 --> 08:29.980
But to be very sure that the position you're calculating exists on your nav mesh.

08:30.910 --> 08:37.960
Otherwise, you might end up with issues when you try and set the location for your agent to move towards

08:37.960 --> 08:41.590
to a position that actually isn't on the nav mesh.

08:41.590 --> 08:46.780
So just make sure you've got a huge nav mesh or that you keep these values reasonable.

08:47.170 --> 08:52.620
Let's just save that at 50 varieties and let's have a look how that affects our behavior.

08:52.630 --> 08:53.830
So we'll go back in here.

08:56.860 --> 09:03.940
OK, so exactly what I was just mentioning, you can now see that he tried to produce some points there

09:03.940 --> 09:09.880
and decided to do absolutely nothing initially because of those random values and where it was producing

09:10.150 --> 09:10.870
the circle.

09:11.020 --> 09:22.170
So I guess you can imagine that this guy's radius, we just zoom in on him and zoom out a little bit.

09:22.540 --> 09:24.100
Is that what was happening?

09:24.100 --> 09:30.210
There would have been that the circle was probably around this area here, OK?

09:30.220 --> 09:36.490
And there were points along this part that we were creating, but there is no need for those.

09:36.760 --> 09:42.430
But when we go in this side of the circle, it was creating them and then allowed him to actually turn

09:42.430 --> 09:45.280
around after he stood there and did nothing for a little while.

09:45.460 --> 09:54.610
But if you changed your wandered distance so that it's the circle is like right out in no man's land

09:54.610 --> 10:01.930
out here, then no point on that circle is ever going to be on your nav mesh and therefore it will cause

10:02.380 --> 10:03.060
an issue.

10:03.460 --> 10:09.160
So with that in mind, let's leave our wander as we initially had it.

10:09.460 --> 10:15.600
Let's put our readiest back at, say, 10, I think it was, and the Jidda back down to one.

10:15.610 --> 10:19.760
So let's just make it a little bit nicer, a little bit smaller.

10:19.780 --> 10:24.970
Now, granted, he could walk to the edge of the map and then just stop there.

10:25.300 --> 10:31.660
But as long as you've got enough sort of radius around you, then you'll be able to turn him around

10:31.660 --> 10:32.230
at some point.

10:32.230 --> 10:38.740
Now, if we look at this, the distance for this circle is 20 and then it's going to have a radius of

10:38.740 --> 10:44.080
ten, which means it's not going to go around the original overlap, the agent.

10:44.080 --> 10:50.680
So maybe if we turn this down to ten here as well, we can be assured that the circles are always going

10:50.680 --> 10:54.790
to be slightly offset from the agent, but behind the agent as well.

10:54.790 --> 11:00.790
So the agent is going to turn around and be allowed to turn around on that nav mesh.

11:01.150 --> 11:06.970
If you're not using a nav mesh and you're using like 3D coordinates in a sort of an open, free world,

11:07.300 --> 11:13.650
you know, then fine, you won't have that same problem that you will when you try and run Agent Dot

11:13.660 --> 11:17.110
set destination for a point that doesn't exist.

11:17.480 --> 11:23.160
OK, so that is Wanda and a few of the little nuances to do with Wanda.

11:23.770 --> 11:29.560
And you can see how it's very adjustable just by playing around with these values.
