Now that we've got our car set up with the wheels and it's moving forward and backwards, it's time
to get these tyres steering the car.
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
the wheels.
So open up your drive script.
Now what we're going to require is a maximum turning angle.
So public float and max steer angle and we'll make that equal to 30.
And of course, you can change that to whatever you like.
And we also are going to then pass through a steering value into our go method.
So up here we'll have float steer.
Now this steer will be from the horizontal axis.
So in the update you want to grab a copy of that and then just put steer in there and pass through SX
to our method here.
Now how do we set the steer.
Well, the steer is part of the wheel collider so we can come up here and put wheel collider dot.
Steer angle equals.
Steer like that and the steer has to actually be modified to use the maximum angle.
Now, we did this with the acceleration as far as normalising it between minus one and one.
We'll do the same with the steer.
So steer is going to equal math F clamp steer minus one one like that.
And we also want to bring in our maximum steering angle.
So this is normalizing the value between negative one and one, which is basically the direction or
the amount of steer or both actually.
And then we want steer angle in here like that.
And I've just noticed I didn't put horizontal down here.
I put vertical even though I said horizontal.
Okay.
So there we go.
All right.
So that's going to be the A and the D key.
Okay, so save that.
Now let's go back into unity.
We're going to press play and then we can use the keys to actually rock our tires from side to side
like that.
Now you'll notice that these models have the disc brakes in there and the disc brakes aren't turning
with the tire.
So you can fix that.
Quite simply, if we stop playing and we come into our measures for our wheels, you can either, I
guess, turn off the disc brake if you don't want to see it, or you can change the way that these are
orientated so they can actually have the wheel mesh.
Let's put that under there.
I'll open up the prefab and do this.
So let's go down into our here's the wheels.
And for each of these you just need to re-orientate them.
So take the wheel, add it to the wheel up there, then add the disc brake to the wheel and sort them
around basically.
And that's going to allow the disc brake to actually rotate when we rotate the wheel mesh like that.
Okay, so that's our prefab.
All done.
Let's go back, press play again and now we can turn.
Now we'll notice that disc brake actually works with it as well.
So now we can go backwards and we can go forwards and we can turn now in this car, we currently have
four wheel steering, which might be something that you want, but these cars tend to not have four
wheel steering.
So let's go into here and actually modify our drive script once more.
We're going to put it in a public bool can turn and we'll set that to false.
And then down here in our go, we want to just say if can turn, then we will turn like that.
Now if you wanted to make this possibly a bit more efficient for each time the go runs, which is every
update, we could possibly get rid of this calculation from happening unless we actually need it, which
is then down in here.
Okay, so let's save that and come back into unity.
Now you want to select your front wheels.
So if we go to our colliders, not the measures because it's the colliders that have the drive code
on it we're going to set can turn for these two to true okay I've already got mine there make sure that
you leave the rear wheels not and then that's very flexible so that you can if you've got something
with more than two tyres on it and you want them at the front, then you want them to change.
You can set that up.
How would you like?
Okay, so let's have a no go.
Now let's turn.
And then when we drive forward you'll see that the direction of the wheels and if we go backwards,
I should be able to turn around is also influencing where we're going, which is just so nice.
Okay.
So that's our basic car set up.
And now that we have that, it's not us that's doing the driving.
Okay?
This is an eye course.
So it's about creating an eye driver who's going to drive our car, and we'll do that in the next video.