WEBVTT

00:03.140 --> 00:07.370
In the previous lecture, we started on a simple waypoint system.

00:07.370 --> 00:13.820
In this lecture, are we going to work on getting our characters to progressively look at the location

00:13.820 --> 00:17.270
that they're travelling towards rather than snapping around?

00:17.630 --> 00:22.850
So we have to go back into our follow waypoint code and find our look at line.

00:23.300 --> 00:27.980
So I'm just going to comment that out so that you can remember what we're trying to achieve here.

00:28.130 --> 00:32.750
And instead, we're going to use the unity returnee and system.

00:32.750 --> 00:35.800
So let's begin with creating a cartoon.

00:35.810 --> 00:39.070
And so I can turn in stores a rotation.

00:39.080 --> 00:40.640
So turn in.

00:42.100 --> 00:48.070
Look at waypoint and that's going to equal turn in.

00:50.030 --> 00:52.760
Dot look rotation.

00:53.880 --> 00:55.470
Waypoints.

00:56.430 --> 00:59.250
Current waypoint point.

01:00.490 --> 01:03.880
Dot transform dot position.

01:05.150 --> 01:10.040
Minus this dot transform dot position.

01:10.700 --> 01:18.890
So that might seem familiar of getting your goal location minus the position of your character.

01:18.890 --> 01:25.640
If you remember back to developing the vectors that we did where we were finding the direction vector

01:25.640 --> 01:27.650
from your location to the goal.

01:27.650 --> 01:35.240
So this is exactly the same thing you're giving your turn and look at a vector we're just going to use

01:35.240 --> 01:36.740
as a rotation.

01:36.740 --> 01:45.500
So that gives you what you need to rotate through to get from your current rotation of your tank to

01:45.500 --> 01:47.210
facing in the right direction.

01:47.210 --> 01:55.970
Though, we're only going to use a little proportion of this turn in the transform or this dot transform.

01:57.140 --> 02:01.280
Dot rotation is actually stored as a turn in.

02:01.280 --> 02:08.210
So instead of setting it to look at waypoint, which we could, what we're going to do is actually perform

02:08.210 --> 02:09.830
what's called a slurp.

02:10.280 --> 02:20.000
And slurp is spelt like you would expect, which is a spherical interpolation of the actual angle or

02:20.000 --> 02:21.920
the rotation that you're going through.

02:21.920 --> 02:26.390
And it basically means just turning a little bit through the whole angle.

02:26.690 --> 02:29.280
So transform it.

02:30.760 --> 02:32.050
Rotation.

02:32.680 --> 02:35.590
Look at waypoint.

02:37.490 --> 02:45.860
And then we're going to put our time, Delta time in here, which is the amount of rotation that you

02:45.860 --> 02:47.990
want to do through that entire angle.

02:48.020 --> 02:52.110
Let me just put this in front of here to be consistent, since I'm using it throughout.

02:52.130 --> 02:58.010
Now, just like the speed here that you can set as a variable for how much speed you want, you can

02:58.010 --> 03:00.530
also set how much rotation you want.

03:00.530 --> 03:04.790
So let's put in a lot speed here and multiply that.

03:04.790 --> 03:11.600
And then at the top we'll create a public float for Rod's speed.

03:11.600 --> 03:15.620
And let's set that also to ten tens.

03:15.620 --> 03:19.370
Always a good round number to start testing things with.

03:19.700 --> 03:20.060
All right.

03:20.060 --> 03:20.810
So we've got that.

03:20.810 --> 03:24.050
Let's now save it and have a look at the effect.

03:24.530 --> 03:26.860
So we will press play.

03:26.870 --> 03:32.360
And what you're going to find is your tank is going to turn.

03:34.030 --> 03:38.230
Quite smoothly around instead of snapping.

03:38.620 --> 03:43.690
So what do you think's going to happen if we go back to our tank and now we change our rotational speed

03:43.690 --> 03:45.880
down to, say, five?

03:46.240 --> 03:47.440
Press play.

03:49.660 --> 03:50.110
Okay.

03:50.110 --> 03:51.580
Enough goes the tank.

03:53.420 --> 04:00.350
And don't if you can tell a lot there, but it's taking longer to go through the entire turn.

04:00.410 --> 04:05.510
Let's turn that down even more to one and you should start to really notice it.

04:05.960 --> 04:12.380
It will start taking its time turning, which means you're going to get a much sort of smoother curve

04:12.380 --> 04:14.780
that goes through all of these palm trees.

04:14.780 --> 04:20.270
So you can see how he's starting to wiggle along that path.

04:21.730 --> 04:25.570
Rather than taking the corners tightly as before.

04:29.360 --> 04:29.890
Okay.

04:29.900 --> 04:35.290
Now what happens if we change the rotational speed down to 0.5 and we have another go?

04:35.300 --> 04:36.500
Let's press play.

04:37.970 --> 04:38.760
Okay.

04:38.930 --> 04:39.350
Right.

04:39.350 --> 04:42.460
We have a situation where the tank is circling the waypoint.

04:42.470 --> 04:44.720
Let me just focus in on that for you.

04:45.500 --> 04:46.750
Now, what's happening here?

04:46.760 --> 04:49.550
Well, you've seen this happening before.

04:49.880 --> 04:54.850
We've had it with other characters that won't actually ever get to their goal location.

04:54.860 --> 05:01.880
So what's happening in this instance is that the tank is trying to turn towards the tree, but it's

05:01.880 --> 05:08.810
turning circle isn't tight enough, so it's never, ever going to get within a distance of three of

05:08.810 --> 05:13.460
the tree in order for it to then switch over to the next waypoint.

05:13.460 --> 05:22.190
So you've either got to go back into your code and make your distance threshold here of where you reach

05:22.190 --> 05:24.560
a waypoint much larger.

05:25.220 --> 05:29.720
So if we set this to say ten, I think that should be okay for such a.

05:31.010 --> 05:32.540
Lazy turning vehicle.

05:32.540 --> 05:35.120
Let's see if we can get within ten of that.

05:36.430 --> 05:36.590
Okay.

05:36.700 --> 05:39.280
So now it's considered to have been within ten.

05:39.430 --> 05:41.230
Same for that one there.

05:45.630 --> 05:49.400
But what you can also tell is, though, it's not very accurate.

05:49.440 --> 05:49.590
Okay.

05:49.680 --> 05:55.440
Because you're letting him have a lot of leeway as to whether he's reached a waypoint or not.

05:56.910 --> 05:59.250
So I guess it's up to the effect that you actually want.

05:59.250 --> 06:04.410
If you want them to sort of have quite a large turning circle, then you'll have to give them a little

06:04.410 --> 06:11.160
bit more leeway in how they get with their accuracy to those actual palm trees.

06:11.160 --> 06:13.140
But I'm going to set that back down to three.

06:13.440 --> 06:22.830
Save that in the code and I will set my tax rotation back to, let's say, five so that we know now

06:22.830 --> 06:24.840
that we're going to hit these waypoints.

06:24.840 --> 06:32.640
But just know that if you ever get your tank or car or whatever you've got near a waypoint and it's

06:32.640 --> 06:35.950
just going round and round and round the waypoint, it's because of your accuracy.

06:35.950 --> 06:43.380
You can't hit the waypoint because it's not able to turn tight enough to reach that particular distance

06:43.380 --> 06:46.680
that you're wanting it to right now.

06:46.680 --> 06:52.410
I'm sure you're ready to put your script onto each of the tanks and have them race around the track.

06:52.410 --> 06:58.890
So get hold of your follow waypoint script and start putting it on each of your tanks.

06:59.160 --> 07:05.760
And don't forget to populate each of those waypoint arrays with all of the palm trees.

07:11.090 --> 07:14.180
So when we press play, off they go.

07:14.180 --> 07:19.550
Now, we don't have any physics elements on these at all, so they're just going to be on top of each

07:19.550 --> 07:24.380
other, which really makes it quite a dull kind of simulation.

07:24.500 --> 07:30.530
So what we're going to do in the next video is actually come back and start adding some physics elements

07:30.530 --> 07:32.030
to our tanks.
