WEBVTT

00:05.010 --> 00:10.500
Now that we've got our car set up with the wheels and it's moving forward and backwards, it's time

00:10.500 --> 00:14.290
to get these tyres steering the car.

00:14.310 --> 00:21.330
So what we're going to do is modify our code so we can use the side arrow keys or the and keys to turn

00:21.330 --> 00:22.100
the wheels.

00:22.110 --> 00:24.600
So open up your drive script.

00:24.630 --> 00:28.800
Now what we're going to require is a maximum turning angle.

00:28.800 --> 00:39.330
So public float and max steer angle and we'll make that equal to 30.

00:39.480 --> 00:42.030
And of course, you can change that to whatever you like.

00:42.030 --> 00:48.390
And we also are going to then pass through a steering value into our go method.

00:48.390 --> 00:51.030
So up here we'll have float steer.

00:51.060 --> 00:54.720
Now this steer will be from the horizontal axis.

00:55.170 --> 01:05.970
So in the update you want to grab a copy of that and then just put steer in there and pass through SX

01:06.600 --> 01:08.310
to our method here.

01:08.340 --> 01:10.230
Now how do we set the steer.

01:10.260 --> 01:16.290
Well, the steer is part of the wheel collider so we can come up here and put wheel collider dot.

01:17.650 --> 01:20.770
Steer angle equals.

01:23.720 --> 01:31.660
Steer like that and the steer has to actually be modified to use the maximum angle.

01:31.670 --> 01:37.550
Now, we did this with the acceleration as far as normalising it between minus one and one.

01:37.550 --> 01:39.110
We'll do the same with the steer.

01:39.110 --> 01:47.150
So steer is going to equal math F clamp steer minus one one like that.

01:47.360 --> 01:52.430
And we also want to bring in our maximum steering angle.

01:52.430 --> 01:58.550
So this is normalizing the value between negative one and one, which is basically the direction or

01:58.550 --> 02:00.950
the amount of steer or both actually.

02:00.950 --> 02:05.600
And then we want steer angle in here like that.

02:05.900 --> 02:08.810
And I've just noticed I didn't put horizontal down here.

02:08.810 --> 02:11.330
I put vertical even though I said horizontal.

02:12.320 --> 02:12.650
Okay.

02:12.650 --> 02:13.670
So there we go.

02:13.670 --> 02:14.000
All right.

02:14.000 --> 02:15.680
So that's going to be the A and the D key.

02:15.680 --> 02:16.670
Okay, so save that.

02:16.670 --> 02:18.860
Now let's go back into unity.

02:18.860 --> 02:28.130
We're going to press play and then we can use the keys to actually rock our tires from side to side

02:28.130 --> 02:29.480
like that.

02:29.570 --> 02:36.500
Now you'll notice that these models have the disc brakes in there and the disc brakes aren't turning

02:36.500 --> 02:38.240
with the tire.

02:38.240 --> 02:40.070
So you can fix that.

02:40.070 --> 02:46.910
Quite simply, if we stop playing and we come into our measures for our wheels, you can either, I

02:46.910 --> 02:52.430
guess, turn off the disc brake if you don't want to see it, or you can change the way that these are

02:52.430 --> 02:56.000
orientated so they can actually have the wheel mesh.

02:56.000 --> 02:58.640
Let's put that under there.

02:59.240 --> 03:01.220
I'll open up the prefab and do this.

03:01.220 --> 03:05.390
So let's go down into our here's the wheels.

03:05.750 --> 03:11.150
And for each of these you just need to re-orientate them.

03:11.150 --> 03:17.390
So take the wheel, add it to the wheel up there, then add the disc brake to the wheel and sort them

03:17.390 --> 03:18.500
around basically.

03:18.500 --> 03:29.390
And that's going to allow the disc brake to actually rotate when we rotate the wheel mesh like that.

03:29.540 --> 03:31.430
Okay, so that's our prefab.

03:31.430 --> 03:31.940
All done.

03:31.940 --> 03:36.830
Let's go back, press play again and now we can turn.

03:36.830 --> 03:40.520
Now we'll notice that disc brake actually works with it as well.

03:40.520 --> 03:50.300
So now we can go backwards and we can go forwards and we can turn now in this car, we currently have

03:50.300 --> 03:57.710
four wheel steering, which might be something that you want, but these cars tend to not have four

03:57.710 --> 03:58.640
wheel steering.

03:58.640 --> 04:02.900
So let's go into here and actually modify our drive script once more.

04:02.900 --> 04:08.870
We're going to put it in a public bool can turn and we'll set that to false.

04:09.140 --> 04:18.560
And then down here in our go, we want to just say if can turn, then we will turn like that.

04:18.560 --> 04:24.200
Now if you wanted to make this possibly a bit more efficient for each time the go runs, which is every

04:24.200 --> 04:30.800
update, we could possibly get rid of this calculation from happening unless we actually need it, which

04:30.800 --> 04:32.570
is then down in here.

04:32.840 --> 04:36.980
Okay, so let's save that and come back into unity.

04:36.980 --> 04:39.710
Now you want to select your front wheels.

04:39.710 --> 04:46.070
So if we go to our colliders, not the measures because it's the colliders that have the drive code

04:46.070 --> 04:53.030
on it we're going to set can turn for these two to true okay I've already got mine there make sure that

04:53.030 --> 04:57.860
you leave the rear wheels not and then that's very flexible so that you can if you've got something

04:57.860 --> 05:02.420
with more than two tyres on it and you want them at the front, then you want them to change.

05:02.420 --> 05:04.100
You can set that up.

05:04.100 --> 05:04.970
How would you like?

05:05.090 --> 05:07.430
Okay, so let's have a no go.

05:07.430 --> 05:08.690
Now let's turn.

05:08.690 --> 05:14.870
And then when we drive forward you'll see that the direction of the wheels and if we go backwards,

05:14.870 --> 05:21.740
I should be able to turn around is also influencing where we're going, which is just so nice.

05:22.470 --> 05:22.860
Okay.

05:22.860 --> 05:25.410
So that's our basic car set up.

05:25.410 --> 05:28.890
And now that we have that, it's not us that's doing the driving.

05:28.900 --> 05:29.180
Okay?

05:29.250 --> 05:30.480
This is an eye course.

05:30.480 --> 05:36.510
So it's about creating an eye driver who's going to drive our car, and we'll do that in the next video.
