At this point in the section, we've got a car that's going around the course, albeit not particularly
elegant in some instances, depending on the settings that you've got for it.
So we're going to look at is an easier way of setting those settings rather than going to the wheel
colliders, then going to this script and that script and all that.
You want to put them all in the one place, all of these settings, so that you can tweak cars and you
can tweak them individually as well once you've sort of figured out what's going to work for you.
Now you can do what I'm about to show you with any settings that are throughout the script.
So I've already put these into the control and I'm going to step through them with you.
So open up your air controller at the very top.
I've put in this heading that's going to show in the inspector for the car settings.
Now I also have this other heading here which I've realised actually doesn't appear in the inspector,
even though I've still got it typed in there.
So I might just like get rid of it for now.
I just wanted it for a spacer, but that doesn't matter.
So we've got some settings that were already in here, others that I've added and others I've brought
from elsewhere.
So we've had things like the steering sensitivity and the look ahead.
Now I've made that into a public float.
These three things are on the drive script.
If we go over to the drive script and go up to the top here, these are those values we were setting
on every wheel and we don't actually want to have to do that.
Like by going in and setting them all.
So by doing it in here, we can pass them through.
You still need them on the drive script.
Okay.
The other thing I've put in here is the value for the anti roll as well, which is on your anti roll
script back here that we're setting and you can set that individually.
This still needs to be here.
We're just setting it up here and passing it through and these other ones.
So I've got accelerate max, corner brake corner max and accelerate velocity threshold and break velocity
threshold.
Those ones, they're are going to be used down in the script where we've actually got some hard coded
versions.
So add all of these in and these are just the default settings that I'm putting in so that they show
up in the inspector for you.
Of course you can change them if you've found better ones than I've got.
So where do we set these?
Let's come down into, first of all, the start where some things are brought through.
Okay?
So we can set up the values for the wheels down here in this for each.
So we get the drive script up here and we put it in array from all of those wheel collider objects.
And then we can just access the max torque, the steer angle and the max brake torque and set those
values in there.
The other value I've got in here that I'm setting is the anti roll script.
So the anti script, anti roll is set to the anti roll that we're bringing in to this script just here.
Okay.
So let's go down to the other values that we've got inside of the update to do with the generation of
these corners and the corner factors.
So if you remember these two if statements for the acceleration and the brake value, we had hardcoded
values for the acceleration corner max and the acceleration velocity threshold.
And you can see I've just replaced those with the variables that we're passing through at the top and
a piece of code that I still had left over was this braking here.
So if you don't have that uncomment and you might want to comment it out or in fact just delete it because
we're not using distance to target any more because we're using our tracker object.
Okay.
So once you've got all of those in, if you save your script, you can go back into unity and select
your car.
And those values are going to show up here in the arrow controller.
So you can set those for each individual car and that's going to deal with your wheel colliders, which
is a lot less effort and more consistent than the way we had them before.
Now, if these values in here are different to what you had in the script, that's because I've already
been playing around and setting these values for myself.
Now, let's also have a look at our tracker object.
I'm using my tracker, if you remember up in Progress Tracker, let's move up here.
We talked about moving the tracker using the time.
Now I had a value of one in here.
Now that can appear a little bit jerky on the track as it's going.
Around for you and you might have played around with this value to get different speeds for that tracker.
Bearing in mind a translate on my computer might actually look a little bit slower than on yours because
I'm actually recording the screen, which tends to slow things down as far as the way the physics are
reacting and that they should be very similar.
They will also depend on where your waypoints are.
So if your waypoints aren't in exactly the same place as mine are, then you are going to get slightly
different things going on.
But something we can control is this progress tracker.
Now, as you can see, what I've done is I've got 15 multiplied by time, delta time.
So by multiplying something by time, delta time, it's going to smooth out our speed value depending
on the frame rate of unity as it's running it.
So it should be the same on every single machine.
So we've got this in here.
Let's just have a look at what happens.
So I'm saving this.
Let's go back into unity now.
We're going to press play once that finishes compiling and off we go.
Now it immediately for me even looks a little bit smoother.
Of course, it's still going to be a little jerky looking when it gets to the end of its tether because
it's, you know, it's trying to stay at that particular distance and it will actually stop from time
to time.
Now, at this point, my car with particular settings is slowing down a hell of a lot around the corners.
That's still not too bad.
But something happens here.
And if you watch, have a look what you get the car.
Remember, it's accelerating.
But our tracker, it's not accelerating, okay?
It's it's going at a consistent speed.
So the car actually catches up to it.
Now, while it does that little loopy loop around the car and keeps going, I guess it doesn't really
affect things too much.
The car gets slightly confused, but it's not ideal, is it?
We actually want this track to stay ahead of the car and therefore we want to sort of control if it's
going to speed up or slow down based on where it is with respect to the car.
So let's go back into the air controller and we're going to update our progress tracker code just a
little bit.
So instead, we're going to have a variable for its speed up the top here.
I'm going to put tracker speed.
Of course, you can put this variable up the top with the others if you'd like.
I'm putting it here so you can just see it.
Let me put 15 in there.
Okay.
Now, we're also going to say at this point, if the distance between the car and look ahead or is greater
than look ahead, this is when we're not going to move at all.
So before we decide we're not moving anywhere at all, we will just in here decrease the speed of the
tracker.
So tracker speed.
Minus equals 1.0 f like that.
Now, you could still run it through without this return, or you could just return until the next time.
We're saying that it's greater than the lookahead and when it is greater, then look ahead.
We're not really interested in looking ahead towards it at that new position, so we can just simply
return now after this will also test if it's got too close to our car.
So we're going to put if vector three dot distance.
This doc transformed position.
Tracker transformed position.
And you can set this to something.
I'm going to sort of base it on the look ahead.
So if it's look ahead, it's closer than look ahead, divided by 2.0 F or half the distance to the maximum
that we've set.
Then we're going to go tracker speed plus equals 1.0 f I'm actually going to speed it up so then we
can use this track of speed down inside of our translate.
And now we have if we put this here, track a speed, a variable speed for our tracker, which will
be a little bit more adjustable.
So let's have a look now at the performance that we get out of this.
Now, take note of my car settings.
If you want to use those, of course you can use your own in these places.
I've increased my brake talk a fair bit to give us a fair bit of oomph when we need to break.
The steering sensitivity is up just a tiny bit look ahead of reduced that down to 20 and I think the
others are the brake quantum max is five but you can just play around with those.
But now let's have a look at our tracker's progress and see how that really changes the behaviour of
what we get right now.
Initially the tracker is going to be within half a distance of the car.
That's why it slows down initially.
But once we're past that first waypoint, off it goes.
Now 20 is quite close.
The car will catch up to it before it gets to the corner.
And I don't mind that behaviour actually because it means that when that capsule quickly zips around
the corner to the next waypoint, it provides a steep enough angle that the brakes are going to come
on.
Now you can see where speeding up and almost caught it then, but it then went ahead and sped ahead
of the car.
Now those values for the tracker and where it actually goes and how fast it goes with respect to the
car, you can change.
Feel free to change that.
If you want to go a little bit faster, make it go a little bit faster.
I might go a bit lower, slower or make it go a bit slower.
And that might even be values that you put in these car settings.
So again, these are not all hard set values that you must have or you mustn't have.
And it's not an extensive list of all the different values that you can have for your car.
And of course, you could feed through to your wheels.
We'll colliders down here the values for all of these as well.
Your springs, you've got your mass in the radius.
You probably don't want to mess around with those because that's the actual set up for the tyre.
But these values are here to do with friction and spring.
That's something else that you could pass through via this settings here if you want to play around
with those.
Okay.
When we come back in the next lecture, we will look at colliding with other cars and putting in some
avoidance code.