WEBVTT

00:05.030 --> 00:13.370
In the previous video we were looking at time and the rate at which the updates happen, the late update,

00:13.370 --> 00:17.090
the fixed update and the basic update.

00:17.210 --> 00:24.740
And we've added in one atom, it's actually walking in real time based on your computer's clock, not

00:24.740 --> 00:28.670
actually the speed at which these updates get run.

00:28.760 --> 00:37.700
So how do we make sure we have consistency on the movement of things that are happening inside of those

00:37.700 --> 00:38.870
other update loops?

00:38.870 --> 00:43.760
Because we don't really want to keep track of time like we have with the second atom.

00:43.880 --> 00:51.260
Now, we've already used this principle in previous lectures, and I'm not sure if you remember, but

00:51.260 --> 01:00.080
it was when we put in time, dot delta time, which is adding in the time that has elapsed since the

01:00.080 --> 01:01.730
last frame.

01:02.180 --> 01:02.660
Okay.

01:02.660 --> 01:07.600
So let's put that into the update movement instead.

01:07.610 --> 01:10.490
So going to update move in the end here.

01:10.490 --> 01:17.240
Instead of putting that, let's put time dot delta time in there, save that.

01:17.390 --> 01:19.520
Now let's go back into unity.

01:19.520 --> 01:26.690
I'm going to press play, compare the seconds atom, which is this guy at the end with the update one

01:26.690 --> 01:27.500
here.

01:27.620 --> 01:30.830
So this is where we're kind of calculating time by hand.

01:30.830 --> 01:34.400
This is when we're using Unity's own principle of time.

01:34.400 --> 01:38.600
What you'll find is they move at exactly the same rate.

01:38.600 --> 01:44.030
These guys are still lagging behind based on how often they get updated.

01:45.440 --> 01:45.860
Okay.

01:45.860 --> 01:52.640
So that means in principle, if we go back to these other ones, so our fixed update and put in here

01:52.670 --> 02:06.980
time dot delta time and the same save that in our late update time dot delta time and save that and

02:06.980 --> 02:07.790
press play.

02:07.790 --> 02:17.060
We'll have now updated these guys with time rather than CPU, GPU cycles or whatever is running those

02:17.060 --> 02:17.720
loops.

02:17.720 --> 02:22.070
And you can see that we have nice consistent movement.

02:23.580 --> 02:26.590
I've now got a bit of a challenge for you.

02:26.610 --> 02:33.270
What I'd like you to do is modify each of these scripts so that we can actually add in a speed value

02:33.270 --> 02:38.940
so that we can get the atoms moving faster because you don't necessarily want them going at just like

02:38.940 --> 02:40.320
one meter per second.

02:40.530 --> 02:44.370
You might want them going at five meters per second or half a metre per second.

02:44.610 --> 02:49.980
So we've already done this as well in previous videos, but we never sort of investigated it like we

02:49.980 --> 02:50.730
have now.

02:50.760 --> 02:57.030
So if you can remember back and look back yourself into the other videos of where we've done this and

02:57.030 --> 03:01.470
add that method into these so we can set the speed.

03:01.480 --> 03:03.840
Okay, so pause the video now go off and do that.

03:03.840 --> 03:07.890
And when we come back, I'll remind you how we did it previously.

03:08.520 --> 03:09.440
Welcome back.

03:09.450 --> 03:10.930
How did you go with that?

03:10.950 --> 03:19.260
Did you remember that we had a public value in here called speed and let's have it as a float.

03:20.310 --> 03:29.460
And we can set that in the inspector or we can set it in here and let's make this 0.5 F so it is sort

03:29.460 --> 03:32.250
of half the speed of the others.

03:32.250 --> 03:39.180
This is in the update move and then we just simply multiply our time by that to either increase it or

03:39.180 --> 03:40.140
decrease it.

03:40.320 --> 03:44.460
Okay, so let's save this update moves the only one I've done.

03:44.460 --> 03:50.430
So the one at the bottom of the screen should be actually going at half the rate of the others.

03:50.670 --> 03:55.230
So let's press play and just have a look at how this works.

03:55.440 --> 03:57.690
So off they go.

03:57.690 --> 04:01.920
And you can see he's moving slower.

04:01.920 --> 04:07.470
But the nice thing about this is if you then set the same speed on everybody else, they will all be

04:07.470 --> 04:09.060
consistently slower.

04:09.060 --> 04:15.180
So we don't get weird speed ups or slow downs that we don't want.

04:15.180 --> 04:21.660
So let's go into all of these others and even in our seconds update, we can put that in there as well.

04:21.660 --> 04:24.390
So let me grab hold of this.

04:24.390 --> 04:28.260
I'm just going to copy that out of there and put it up here.

04:28.320 --> 04:35.250
So we put that there and then of course, we multiply by speed down here, make sure that you put brackets

04:35.250 --> 04:44.670
around this value and then we're going to save that, go into the fixed update and add that in there,

04:45.300 --> 04:46.890
then multiply by it.

04:48.440 --> 04:56.690
And then lastly, save that, go into the next one late update, put that in there and multiply it by

04:56.690 --> 04:57.740
speed.

04:58.340 --> 05:01.850
So save that flip back into unity.

05:01.850 --> 05:07.550
And let's have a look at the movement of these guys.

05:09.290 --> 05:09.710
Okay.

05:09.740 --> 05:10.580
There they go.

05:10.610 --> 05:17.220
Now, you'll remember when we were rotating the tank around, when we were moving the tank.

05:17.240 --> 05:22.250
In the previous lectures, there was also a rotation speed.

05:22.250 --> 05:29.570
So whenever your characters need to actually rotate, you can also have a rotation speed and multiply

05:29.570 --> 05:38.270
that by time delta time inside of these loops so that you have a consistent turning speed as well.

05:38.270 --> 05:45.380
So the key message out of all this is that unless you're going to keep track of time yourself, then

05:45.380 --> 05:52.400
the best way to do it is really use time, delta time and include that in any of your movement or turning

05:52.400 --> 05:59.210
calculations that you're doing to ensure that all of your characters are moving at a consistent speed

05:59.210 --> 06:05.360
and the players of your game are going to get the same experience no matter what machine they're on.
