WEBVTT

00:04.980 --> 00:10.950
At this point in the section, we've got a car that's going around the course, albeit not particularly

00:10.950 --> 00:15.120
elegant in some instances, depending on the settings that you've got for it.

00:15.150 --> 00:20.700
So we're going to look at is an easier way of setting those settings rather than going to the wheel

00:20.720 --> 00:23.280
colliders, then going to this script and that script and all that.

00:23.280 --> 00:28.470
You want to put them all in the one place, all of these settings, so that you can tweak cars and you

00:28.470 --> 00:32.730
can tweak them individually as well once you've sort of figured out what's going to work for you.

00:32.760 --> 00:38.430
Now you can do what I'm about to show you with any settings that are throughout the script.

00:38.430 --> 00:42.930
So I've already put these into the control and I'm going to step through them with you.

00:42.930 --> 00:46.410
So open up your air controller at the very top.

00:46.410 --> 00:52.050
I've put in this heading that's going to show in the inspector for the car settings.

00:52.140 --> 00:58.170
Now I also have this other heading here which I've realised actually doesn't appear in the inspector,

00:58.170 --> 01:00.450
even though I've still got it typed in there.

01:00.450 --> 01:02.790
So I might just like get rid of it for now.

01:02.790 --> 01:06.270
I just wanted it for a spacer, but that doesn't matter.

01:06.360 --> 01:12.930
So we've got some settings that were already in here, others that I've added and others I've brought

01:12.930 --> 01:14.060
from elsewhere.

01:14.070 --> 01:18.900
So we've had things like the steering sensitivity and the look ahead.

01:18.900 --> 01:21.990
Now I've made that into a public float.

01:22.140 --> 01:27.150
These three things are on the drive script.

01:27.150 --> 01:32.520
If we go over to the drive script and go up to the top here, these are those values we were setting

01:32.520 --> 01:37.920
on every wheel and we don't actually want to have to do that.

01:37.920 --> 01:39.660
Like by going in and setting them all.

01:39.660 --> 01:42.480
So by doing it in here, we can pass them through.

01:42.510 --> 01:45.000
You still need them on the drive script.

01:45.210 --> 01:45.960
Okay.

01:46.380 --> 01:52.470
The other thing I've put in here is the value for the anti roll as well, which is on your anti roll

01:52.470 --> 01:56.790
script back here that we're setting and you can set that individually.

01:56.820 --> 01:58.500
This still needs to be here.

01:58.500 --> 02:03.510
We're just setting it up here and passing it through and these other ones.

02:03.510 --> 02:12.210
So I've got accelerate max, corner brake corner max and accelerate velocity threshold and break velocity

02:12.210 --> 02:12.600
threshold.

02:12.600 --> 02:18.300
Those ones, they're are going to be used down in the script where we've actually got some hard coded

02:18.300 --> 02:19.080
versions.

02:19.080 --> 02:25.110
So add all of these in and these are just the default settings that I'm putting in so that they show

02:25.110 --> 02:27.450
up in the inspector for you.

02:27.480 --> 02:31.860
Of course you can change them if you've found better ones than I've got.

02:32.130 --> 02:34.320
So where do we set these?

02:34.320 --> 02:40.380
Let's come down into, first of all, the start where some things are brought through.

02:40.620 --> 02:41.130
Okay?

02:41.130 --> 02:48.180
So we can set up the values for the wheels down here in this for each.

02:48.300 --> 02:56.430
So we get the drive script up here and we put it in array from all of those wheel collider objects.

02:56.430 --> 03:02.670
And then we can just access the max torque, the steer angle and the max brake torque and set those

03:02.670 --> 03:03.960
values in there.

03:03.960 --> 03:09.090
The other value I've got in here that I'm setting is the anti roll script.

03:09.090 --> 03:17.460
So the anti script, anti roll is set to the anti roll that we're bringing in to this script just here.

03:18.030 --> 03:18.390
Okay.

03:18.390 --> 03:28.530
So let's go down to the other values that we've got inside of the update to do with the generation of

03:28.530 --> 03:30.180
these corners and the corner factors.

03:30.180 --> 03:35.610
So if you remember these two if statements for the acceleration and the brake value, we had hardcoded

03:35.610 --> 03:42.120
values for the acceleration corner max and the acceleration velocity threshold.

03:42.270 --> 03:49.050
And you can see I've just replaced those with the variables that we're passing through at the top and

03:49.050 --> 03:52.920
a piece of code that I still had left over was this braking here.

03:53.190 --> 03:59.070
So if you don't have that uncomment and you might want to comment it out or in fact just delete it because

03:59.070 --> 04:05.940
we're not using distance to target any more because we're using our tracker object.

04:06.150 --> 04:06.540
Okay.

04:06.540 --> 04:15.300
So once you've got all of those in, if you save your script, you can go back into unity and select

04:15.300 --> 04:16.530
your car.

04:17.730 --> 04:22.230
And those values are going to show up here in the arrow controller.

04:22.230 --> 04:28.680
So you can set those for each individual car and that's going to deal with your wheel colliders, which

04:28.680 --> 04:32.820
is a lot less effort and more consistent than the way we had them before.

04:32.820 --> 04:37.380
Now, if these values in here are different to what you had in the script, that's because I've already

04:37.380 --> 04:41.310
been playing around and setting these values for myself.

04:41.460 --> 04:46.770
Now, let's also have a look at our tracker object.

04:47.310 --> 04:52.290
I'm using my tracker, if you remember up in Progress Tracker, let's move up here.

04:52.770 --> 04:57.240
We talked about moving the tracker using the time.

04:57.240 --> 05:00.750
Now I had a value of one in here.

05:00.750 --> 05:04.200
Now that can appear a little bit jerky on the track as it's going.

05:04.420 --> 05:10.430
Around for you and you might have played around with this value to get different speeds for that tracker.

05:10.450 --> 05:16.150
Bearing in mind a translate on my computer might actually look a little bit slower than on yours because

05:16.150 --> 05:21.310
I'm actually recording the screen, which tends to slow things down as far as the way the physics are

05:21.310 --> 05:24.330
reacting and that they should be very similar.

05:24.340 --> 05:29.200
They will also depend on where your waypoints are.

05:29.200 --> 05:34.240
So if your waypoints aren't in exactly the same place as mine are, then you are going to get slightly

05:34.240 --> 05:36.220
different things going on.

05:36.220 --> 05:38.920
But something we can control is this progress tracker.

05:38.920 --> 05:44.860
Now, as you can see, what I've done is I've got 15 multiplied by time, delta time.

05:44.860 --> 05:52.330
So by multiplying something by time, delta time, it's going to smooth out our speed value depending

05:52.330 --> 05:56.140
on the frame rate of unity as it's running it.

05:56.140 --> 05:59.440
So it should be the same on every single machine.

05:59.920 --> 06:01.990
So we've got this in here.

06:02.230 --> 06:05.020
Let's just have a look at what happens.

06:05.020 --> 06:06.640
So I'm saving this.

06:06.760 --> 06:09.310
Let's go back into unity now.

06:09.310 --> 06:15.790
We're going to press play once that finishes compiling and off we go.

06:15.790 --> 06:19.450
Now it immediately for me even looks a little bit smoother.

06:19.450 --> 06:24.400
Of course, it's still going to be a little jerky looking when it gets to the end of its tether because

06:24.400 --> 06:29.620
it's, you know, it's trying to stay at that particular distance and it will actually stop from time

06:29.620 --> 06:30.400
to time.

06:30.820 --> 06:36.670
Now, at this point, my car with particular settings is slowing down a hell of a lot around the corners.

06:36.670 --> 06:38.620
That's still not too bad.

06:38.620 --> 06:40.210
But something happens here.

06:40.360 --> 06:45.520
And if you watch, have a look what you get the car.

06:45.520 --> 06:47.110
Remember, it's accelerating.

06:47.110 --> 06:50.650
But our tracker, it's not accelerating, okay?

06:50.650 --> 06:54.910
It's it's going at a consistent speed.

06:54.910 --> 06:57.280
So the car actually catches up to it.

06:57.280 --> 07:03.160
Now, while it does that little loopy loop around the car and keeps going, I guess it doesn't really

07:03.160 --> 07:04.510
affect things too much.

07:04.510 --> 07:07.660
The car gets slightly confused, but it's not ideal, is it?

07:07.660 --> 07:13.900
We actually want this track to stay ahead of the car and therefore we want to sort of control if it's

07:13.900 --> 07:18.910
going to speed up or slow down based on where it is with respect to the car.

07:19.030 --> 07:25.600
So let's go back into the air controller and we're going to update our progress tracker code just a

07:25.600 --> 07:26.470
little bit.

07:26.470 --> 07:31.300
So instead, we're going to have a variable for its speed up the top here.

07:31.300 --> 07:33.250
I'm going to put tracker speed.

07:33.250 --> 07:37.270
Of course, you can put this variable up the top with the others if you'd like.

07:37.270 --> 07:39.100
I'm putting it here so you can just see it.

07:39.910 --> 07:42.280
Let me put 15 in there.

07:42.340 --> 07:42.790
Okay.

07:42.790 --> 07:50.830
Now, we're also going to say at this point, if the distance between the car and look ahead or is greater

07:50.830 --> 07:53.410
than look ahead, this is when we're not going to move at all.

07:53.560 --> 08:02.560
So before we decide we're not moving anywhere at all, we will just in here decrease the speed of the

08:02.560 --> 08:02.920
tracker.

08:02.920 --> 08:05.770
So tracker speed.

08:06.860 --> 08:10.820
Minus equals 1.0 f like that.

08:10.850 --> 08:17.240
Now, you could still run it through without this return, or you could just return until the next time.

08:17.270 --> 08:21.140
We're saying that it's greater than the lookahead and when it is greater, then look ahead.

08:21.140 --> 08:28.250
We're not really interested in looking ahead towards it at that new position, so we can just simply

08:28.250 --> 08:33.620
return now after this will also test if it's got too close to our car.

08:33.620 --> 08:38.450
So we're going to put if vector three dot distance.

08:39.780 --> 08:43.080
This doc transformed position.

08:44.100 --> 08:47.760
Tracker transformed position.

08:48.740 --> 08:50.900
And you can set this to something.

08:50.900 --> 08:52.790
I'm going to sort of base it on the look ahead.

08:52.790 --> 09:02.690
So if it's look ahead, it's closer than look ahead, divided by 2.0 F or half the distance to the maximum

09:02.690 --> 09:03.650
that we've set.

09:03.650 --> 09:13.250
Then we're going to go tracker speed plus equals 1.0 f I'm actually going to speed it up so then we

09:13.250 --> 09:17.480
can use this track of speed down inside of our translate.

09:17.480 --> 09:26.150
And now we have if we put this here, track a speed, a variable speed for our tracker, which will

09:26.150 --> 09:28.250
be a little bit more adjustable.

09:28.250 --> 09:33.530
So let's have a look now at the performance that we get out of this.

09:34.040 --> 09:36.680
Now, take note of my car settings.

09:36.680 --> 09:42.620
If you want to use those, of course you can use your own in these places.

09:42.620 --> 09:47.450
I've increased my brake talk a fair bit to give us a fair bit of oomph when we need to break.

09:47.450 --> 09:55.550
The steering sensitivity is up just a tiny bit look ahead of reduced that down to 20 and I think the

09:55.550 --> 10:00.230
others are the brake quantum max is five but you can just play around with those.

10:00.230 --> 10:05.900
But now let's have a look at our tracker's progress and see how that really changes the behaviour of

10:05.900 --> 10:07.220
what we get right now.

10:07.220 --> 10:11.240
Initially the tracker is going to be within half a distance of the car.

10:11.240 --> 10:12.920
That's why it slows down initially.

10:12.920 --> 10:16.490
But once we're past that first waypoint, off it goes.

10:16.490 --> 10:18.590
Now 20 is quite close.

10:18.590 --> 10:22.010
The car will catch up to it before it gets to the corner.

10:22.010 --> 10:27.620
And I don't mind that behaviour actually because it means that when that capsule quickly zips around

10:27.620 --> 10:34.010
the corner to the next waypoint, it provides a steep enough angle that the brakes are going to come

10:34.010 --> 10:34.490
on.

10:34.490 --> 10:40.910
Now you can see where speeding up and almost caught it then, but it then went ahead and sped ahead

10:40.910 --> 10:42.010
of the car.

10:42.020 --> 10:50.390
Now those values for the tracker and where it actually goes and how fast it goes with respect to the

10:50.390 --> 10:52.730
car, you can change.

10:52.730 --> 10:53.600
Feel free to change that.

10:53.600 --> 10:56.160
If you want to go a little bit faster, make it go a little bit faster.

10:56.160 --> 10:59.570
I might go a bit lower, slower or make it go a bit slower.

10:59.570 --> 11:03.200
And that might even be values that you put in these car settings.

11:03.530 --> 11:09.770
So again, these are not all hard set values that you must have or you mustn't have.

11:10.220 --> 11:14.060
And it's not an extensive list of all the different values that you can have for your car.

11:14.060 --> 11:18.260
And of course, you could feed through to your wheels.

11:18.260 --> 11:23.600
We'll colliders down here the values for all of these as well.

11:23.600 --> 11:27.170
Your springs, you've got your mass in the radius.

11:27.170 --> 11:31.010
You probably don't want to mess around with those because that's the actual set up for the tyre.

11:31.310 --> 11:34.400
But these values are here to do with friction and spring.

11:34.820 --> 11:42.470
That's something else that you could pass through via this settings here if you want to play around

11:42.470 --> 11:43.640
with those.

11:43.790 --> 11:44.390
Okay.

11:44.390 --> 11:50.540
When we come back in the next lecture, we will look at colliding with other cars and putting in some

11:50.540 --> 11:52.040
avoidance code.
