WEBVTT

00:02.640 --> 00:05.980
Isaac Newton came up with a set of three laws of motion.

00:06.000 --> 00:13.170
The most famous is that of f equals ma or force equals mass multiplied by acceleration.

00:13.200 --> 00:19.740
Or more importantly for us, the rearrangement of acceleration equals force divided by mass.

00:20.160 --> 00:26.250
This is extremely important to keep in mind, especially when designing vehicle physics, because what

00:26.250 --> 00:33.330
it means is that to accelerate a mass, the larger the mass, the more force required, and that the

00:33.330 --> 00:37.140
same force on different masses will accelerate differently.

00:37.530 --> 00:45.750
For example, given a car with weight 1000 kilograms and a force of 5000 Newtons, you can obtain an

00:45.750 --> 00:48.570
acceleration of five meters per second squared.

00:48.960 --> 00:56.280
The same force on a 100 kilogram car would result in acceleration of 50 meters per second squared.

00:56.430 --> 00:59.010
What does that mean for our wheel suspension?

00:59.040 --> 01:03.230
Well, we've a spring with an upward force acting on a particular mass.

01:03.240 --> 01:08.340
The greater the mass, the more force the spring requires to give the same upward acceleration to the

01:08.340 --> 01:12.150
car, the bigger the mass, the more compressed the spring.

01:12.180 --> 01:16.650
However, in a vehicle, there are also many other forces to consider.

01:16.680 --> 01:23.130
First, we have the dampening force that we can set that represents a downward force that makes the

01:23.130 --> 01:26.350
spring much more rigid and less likely to bounce.

01:26.370 --> 01:28.740
It slows down its recoil.

01:28.980 --> 01:34.110
And then you also have gravity acting on the car and pushing down on the spring.

01:34.110 --> 01:41.460
So the spring needs to combat both gravity and dampening to give the same effect on different masses.

01:41.820 --> 01:44.070
What does all this mean for you?

01:44.100 --> 01:49.980
Well, what I'm trying to get across, I guess, is that when you start programming the physics in these

01:49.980 --> 01:57.930
systems and working with suspension and springs and different masses that you keep in mind your own

01:57.930 --> 02:06.000
real world experience, you know, you know logically and instinctually how physics works because you're

02:06.000 --> 02:08.910
in that world constantly, all day.

02:09.060 --> 02:15.240
Therefore, don't let your intuition go out the window when you start programming this stuff because

02:15.240 --> 02:18.960
it's all programmed based on real life physics.

02:19.170 --> 02:26.790
So keeping all that in mind and what we've learnt so far about Wheels, I've got a little bit of a challenge

02:26.790 --> 02:33.090
for you, so I've created two duplicates of the tire that we were working with before and just put them

02:33.090 --> 02:33.900
on either side.

02:33.900 --> 02:37.630
So this is the original tire and these are two here.

02:37.650 --> 02:41.220
Now, when I press play, I want to show you what I get.

02:41.430 --> 02:48.690
So what I want you to attempt in this challenge, and that is to make bouncy tires with different suspension

02:48.690 --> 02:49.230
setups.

02:49.260 --> 02:54.480
Now, of course, this isn't going to actually do anything because I need to lift them up into the air.

02:54.480 --> 02:59.940
So let me select all of those tires and I'll just lift them up like this.

03:00.330 --> 03:01.290
Okay.

03:01.290 --> 03:03.420
And press play.

03:08.030 --> 03:08.480
Okay.

03:08.480 --> 03:14.930
We've got a pretty bouncy one over here, a not so bouncy one in the middle, which is the one we had

03:14.930 --> 03:15.710
by default.

03:15.710 --> 03:18.680
And then this one here, which is slightly different to that.

03:18.680 --> 03:21.470
Now, your tires will go through the ground at some point.

03:21.470 --> 03:22.160
Don't worry about that.

03:22.160 --> 03:23.810
We'll fix that up a little bit later.

03:23.810 --> 03:27.290
Let's have another look at the difference between these two here.

03:28.970 --> 03:29.270
Okay.

03:29.270 --> 03:33.890
So this one actually has a softer landing than this one.

03:34.010 --> 03:34.480
Okay.

03:34.490 --> 03:36.080
So there's a reason for that.

03:36.230 --> 03:37.520
So pause the video now.

03:37.520 --> 03:39.920
Give it a go of changing these values.

03:39.920 --> 03:43.400
And when we come back, I'll go through the settings that I've got for these.

03:45.440 --> 03:45.880
Okay.

03:45.890 --> 03:46.940
How did you go with that?

03:46.940 --> 03:51.140
Let's have a look at this tire here, the one on the left.

03:51.140 --> 03:59.150
Now, you'll notice if I zoom in on it that the collider I've realigned perfectly and I've made the

03:59.150 --> 04:00.950
spring way longer.

04:00.950 --> 04:08.090
That means that as the tire is actually falling, it's being compressed down on this spring.

04:08.090 --> 04:13.190
That's why it falls slower, because it's taking that spring as its lead time.

04:13.190 --> 04:18.530
Now, if we have a look over in the settings for it, in order to set it up like this, I had to increase

04:18.530 --> 04:20.750
the suspension distance to to.

04:20.750 --> 04:26.240
Now when you do that, the offset for the center of the wheel actually changes.

04:26.240 --> 04:32.450
So we have it at what, 0.15 for the other default tire, I believe.

04:32.450 --> 04:33.140
Let's have a look at that.

04:33.140 --> 04:33.560
Yep.

04:34.010 --> 04:40.100
And so what it's going to do is actually move that when you change the size of your suspension because

04:40.100 --> 04:45.230
it needs to put the collider basically in that sort of center part there.

04:45.230 --> 04:47.510
So we need to actually move this up.

04:47.630 --> 04:53.540
So if we put it back to one, then that's going to sit it around the toy.

04:53.540 --> 04:55.400
You always want it to be around the tire.

04:55.400 --> 05:00.260
So the physics looks like it's happening to the actual mesh itself.

05:00.260 --> 05:06.680
If it's not, it doesn't look like the mesh is the thing that is having physics acted upon it because

05:06.680 --> 05:08.180
it's all real fakery, isn't it?

05:08.180 --> 05:12.590
The only thing we're really doing anything to is the collider in the rigid body.

05:12.590 --> 05:14.540
The mesh is just going along for the ride.

05:14.600 --> 05:18.080
Let's have a look at the other one, this one here, which was much bouncier.

05:18.380 --> 05:22.490
So over in the inspector, the suspension is one for that.

05:22.490 --> 05:29.450
And you can see that the spring for the tire is the entire size of the tire or the diameter of the tire.

05:29.480 --> 05:33.560
Now, when I set that to one, I had to change the center offset 2.5.

05:33.560 --> 05:35.660
So it lined up again.

05:35.720 --> 05:40.910
I've also turned the damper down to 450.

05:40.940 --> 05:45.260
The other tires dampers were 4500.

05:45.380 --> 05:46.460
Now what does that mean?

05:46.460 --> 05:53.510
Well, the higher the dampening on it, then the greater the force is pushing back against the spring.

05:53.510 --> 05:59.030
So you can imagine the dampening as it gets higher, you get a more rigid or firm spring.

05:59.030 --> 06:01.970
It's not such a like really, really bouncy spring.

06:01.970 --> 06:08.000
So that's why this tire over here, this one here is actually quite bouncy because we've turned that

06:08.000 --> 06:09.620
dampening right down.

06:09.620 --> 06:13.130
So it's like a car that's got really bad, worn out suspension.

06:13.130 --> 06:18.380
The dampening on those suspensions, you know, it wears down over time, which is why you have to get

06:18.380 --> 06:19.430
those repaired.

06:19.580 --> 06:20.150
Okay.

06:20.150 --> 06:27.860
So moving on, we're now going to write some script with some physics in it to move the tire.

06:27.860 --> 06:34.400
So first of all, I'm actually just going to delete my extra tires that I created and then grab that

06:34.400 --> 06:40.310
tire that we've got left and we'll bring it down onto the ground because it needs to drive on the ground

06:40.310 --> 06:41.120
just there.

06:41.330 --> 06:47.780
And let's go ahead and create a new script down in our assets folder.

06:47.780 --> 06:54.410
So C-sharp script, let's call it drive and let's open that up, right?

06:54.410 --> 06:58.220
So this drive script will go onto each wheel.

06:58.220 --> 07:04.580
That means that the game object holding onto it, the collider that is, needs to have access to it.

07:04.580 --> 07:07.220
So we want a public wheel.

07:08.530 --> 07:09.400
Collider.

07:09.610 --> 07:15.700
WC And then we also want the amount of force that we're going to add.

07:15.700 --> 07:19.900
So public float and that will be talk.

07:21.020 --> 07:22.790
Equals 200.

07:24.050 --> 07:25.790
Now what is talk?

07:25.790 --> 07:32.480
Will Talk is basically the rotational force and it's calculated using the pivot point.

07:32.480 --> 07:38.330
So that's the point that our tyre is being rotated around or the centre of that collider at this point

07:38.660 --> 07:44.090
and the point of force, which is where that little sphere is that I showed you earlier.

07:44.090 --> 07:51.980
So the distance or the vector from the pivot point to the point of force application is our rotational

07:51.980 --> 07:57.740
vector, and then the actual force that gets applied is applied in a straight line.

07:57.740 --> 08:02.690
So it's the equivalent of normal force, linear force, if you just like pushing something forward because

08:02.690 --> 08:07.490
basically what you're doing as you're rotating the tire is you're constantly pushing it forward.

08:07.910 --> 08:12.680
But that sort of pushing it around because it's sort of stuck to that pivot point.

08:12.680 --> 08:20.300
And so torque is actually the cross product of both of those vectors, R and F, if you're interested

08:20.300 --> 08:23.960
on how that actually gets calculated, we don't need to calculate that.

08:23.960 --> 08:27.440
We just have to set an actual torque amount.

08:28.130 --> 08:30.260
Okay, so let's finish writing this code.

08:30.260 --> 08:38.840
First of all, we're going to get our wheel collider so WC equals this dot get component wheel collider

08:39.920 --> 08:40.700
like that.

08:40.700 --> 08:51.800
And then in our update we're going to use the vertical axis to get an acceleration amount.

08:51.800 --> 09:01.220
So we'll go float a equals input dot get axis and the axis will be the vertical one.

09:01.910 --> 09:03.730
Now this is the up and down arrow key.

09:03.740 --> 09:09.140
So for going forward and backwards and then we'll pass that through to a method that's going to actually

09:09.140 --> 09:11.120
drive the tire forward.

09:11.120 --> 09:21.830
So void go and we'll send through float for acceleration and then in here will put acceleration equals

09:21.830 --> 09:32.480
math f dot clamp and we'll clamp the acceleration between minus one and one, which it should be anyway,

09:32.480 --> 09:40.520
because of this vertical axis that we're passing in, then we'll do a float for thrust torque, which

09:40.520 --> 09:47.480
equals the acceleration multiplied by torque and then we actually apply that to our wheel.

09:47.480 --> 09:58.250
Collider So WC motor torque, which is one of the variables within your wheel collider equals the thrust

09:58.250 --> 10:00.530
torque like that.

10:01.730 --> 10:10.280
Right now, once you've done that, all we need to do is call our go method sending through the acceleration

10:10.280 --> 10:12.800
value that we're getting like that.

10:13.040 --> 10:16.160
Okay, so save this switch back to unity.

10:16.160 --> 10:25.940
And with your truck tire, you need to grab that script and drag and drop it onto the inspector so that

10:25.940 --> 10:27.920
it's now attached to the tire.

10:28.040 --> 10:35.060
And when we press play now, you'll find that you should be able to use your arrow keys.

10:35.150 --> 10:36.980
Don't worry, I know it disappears.

10:37.220 --> 10:40.310
Let's just have a look again as soon as you start moving.

10:41.190 --> 10:41.630
Yep.

10:41.670 --> 10:42.200
Okay.

10:42.210 --> 10:47.010
You use your arrow keys, but you could see the start spinning around and then it falls through the

10:47.010 --> 10:47.830
ground again.

10:47.850 --> 10:48.660
Don't worry about that.

10:48.660 --> 10:50.910
It's going to get fixed shortly.

10:50.910 --> 10:57.540
When we come back in the next lecture, we're actually going to attach our wheel to a makeshift car

10:57.540 --> 10:59.280
and start driving it around.
