In the previous video we were looking at time and the rate at which the updates happen, the late update,
the fixed update and the basic update.
And we've added in one atom, it's actually walking in real time based on your computer's clock, not
actually the speed at which these updates get run.
So how do we make sure we have consistency on the movement of things that are happening inside of those
other update loops?
Because we don't really want to keep track of time like we have with the second atom.
Now, we've already used this principle in previous lectures, and I'm not sure if you remember, but
it was when we put in time, dot delta time, which is adding in the time that has elapsed since the
last frame.
Okay.
So let's put that into the update movement instead.
So going to update move in the end here.
Instead of putting that, let's put time dot delta time in there, save that.
Now let's go back into unity.
I'm going to press play, compare the seconds atom, which is this guy at the end with the update one
here.
So this is where we're kind of calculating time by hand.
This is when we're using Unity's own principle of time.
What you'll find is they move at exactly the same rate.
These guys are still lagging behind based on how often they get updated.
Okay.
So that means in principle, if we go back to these other ones, so our fixed update and put in here
time dot delta time and the same save that in our late update time dot delta time and save that and
press play.
We'll have now updated these guys with time rather than CPU, GPU cycles or whatever is running those
loops.
And you can see that we have nice consistent movement.
I've now got a bit of a challenge for you.
What I'd like you to do is modify each of these scripts so that we can actually add in a speed value
so that we can get the atoms moving faster because you don't necessarily want them going at just like
one meter per second.
You might want them going at five meters per second or half a metre per second.
So we've already done this as well in previous videos, but we never sort of investigated it like we
have now.
So if you can remember back and look back yourself into the other videos of where we've done this and
add that method into these so we can set the speed.
Okay, so pause the video now go off and do that.
And when we come back, I'll remind you how we did it previously.
Welcome back.
How did you go with that?
Did you remember that we had a public value in here called speed and let's have it as a float.
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
of half the speed of the others.
This is in the update move and then we just simply multiply our time by that to either increase it or
decrease it.
Okay, so let's save this update moves the only one I've done.
So the one at the bottom of the screen should be actually going at half the rate of the others.
So let's press play and just have a look at how this works.
So off they go.
And you can see he's moving slower.
But the nice thing about this is if you then set the same speed on everybody else, they will all be
consistently slower.
So we don't get weird speed ups or slow downs that we don't want.
So let's go into all of these others and even in our seconds update, we can put that in there as well.
So let me grab hold of this.
I'm just going to copy that out of there and put it up here.
So we put that there and then of course, we multiply by speed down here, make sure that you put brackets
around this value and then we're going to save that, go into the fixed update and add that in there,
then multiply by it.
And then lastly, save that, go into the next one late update, put that in there and multiply it by
speed.
So save that flip back into unity.
And let's have a look at the movement of these guys.
Okay.
There they go.
Now, you'll remember when we were rotating the tank around, when we were moving the tank.
In the previous lectures, there was also a rotation speed.
So whenever your characters need to actually rotate, you can also have a rotation speed and multiply
that by time delta time inside of these loops so that you have a consistent turning speed as well.
So the key message out of all this is that unless you're going to keep track of time yourself, then
the best way to do it is really use time, delta time and include that in any of your movement or turning
calculations that you're doing to ensure that all of your characters are moving at a consistent speed
and the players of your game are going to get the same experience no matter what machine they're on.