So what's the problem that we'll get with our current code?
Because we're saying an update, do a thing every single frame.
If I'm on a fast computer, then it's going to do that a lot of times and maybe have my car move different
to someone who's on a slower computer and they're doing things less per second.
So we need to understand how to use time, delta time and what it is time to tell to.
Time is a way that unity can tell us how long each frame took to execute.
So on a fast computer, it's going to take a short amount of time for each frame on a slow computer,
it'll take a longer amount of time.
And then when we multiply something by the amount of time it took for each frame, it allows us to make
things frame rate independent.
So in other words, the game behaves the same on fast computers as it will on slow computers.
Or if you're working on a mobile device versus a computer, etc. We want to make sure on everything
we get the same sort of behavior.
So let me give you a little example here, if that hasn't clicked just yet on UPDATE.
So in other words, each frame we want to move our player one unit to the left.
So on a slow computer, we might be getting, say, ten frames per second on a fast computer, we might
be getting, say, 100 frames per second.
And it's going to vary even on a fast computer.
Sometimes it'll be 100 frames, sometimes it'll be 200 frames, some 150 frames, depending upon what
else the computer needs to calculate.
It bounces up and down.
So we need to smooth all of that out.
But look, in my example here, if we have ten frames per second, that means each frame is 0.1 second.
Yes, .1.41.1.
If you do that ten times and reaches 1/2 on a fast computer, if we've got one 100 frames, then each
frame is lasting 0.01 of a second because 100 of the 0.0 ones is going to add up to 1/2.
So the distance per second.
Remember, we're saying move one to the left, every single frame.
So one, and we're doing ten frames per second if we multiply by 0.1.
In other words, how long is a frame we get a value of one.
It'll move one to the left.
If we're saying in a fast computer one frame and we're doing that 100 times per second, then we need
to multiply that by 0.01 to continue to get our one unit.
So that's just a little bit of an example of showing that when we multiply by this time Delta time,
in other words, how long is each frame taking?
We can end up with exactly the same value no matter how fast the computer is running.
And so if I jump back over into my code here, I can find my sticker amount and my move amount.
The steer amount, I've got a value from minus one to plus one because it's on the horizontal axis multiplying
by the sticker amount, which at the moment I think in my code I've got as 0.05.
Yep.
And then I'm finally going to multiply that by time capital T, dot delta, small D and then capital
T time, delta time.
It's as simple as that.
So really simple micro challenge for you here.
Do the same for our move amount times that by time delta time.
Pretty easy.
That's why I didn't give this to you as a challenge.
Slide time.
Delta time.
So now they're both frame rate independent.
However, when we save this jump back over into unity, we're now going to be getting exactly the same
behavior on all computers.
But it's going to have messed up our tuning because we tuned it in a way where we weren't frame rate
independent.
So now when I move, I'm moving, but so slowly you can't even see it.
So now we'd need to go in to change the steer speed and move speed so that our car drives properly.
And this is what I'm going to give to you as a challenge.
So if you will change your speed amount in the inspector to have your car respond to input as you would
like it to.
So in other words, to drive and steer at the right speed.
Pause video.
Take on that challenge now.
Okay.
So first I'm going to do is try increasing it a lot to say 101 hundred just to see what happens there.
I'm going to click on play push forward backwards to fast on the movement and not terrible on the steering.
So I'm going to iterate while in play mode.
I'm going to bring the steer speed down, say to 20 no wrong one.
I'm going to move the move speed down to 20 and then click back in the game window.
Moving, moving.
Not too bad.
I think it's steering a little bit too slowly because it's taking a while to do a big arc like that.
So I'm going to increase my steer speed to 200 click back in the game window.
Now, as I drive around, it's not too bad, you know, that's pretty good.
I could have the steer speed a little bit more.
I think probably to 300.
Want it to feel nice and snappy.
Click back in the game window and remember, okay, now it's feeling kind of cool.
So I need to remember these values.
320 click out of play mode.
I'll lose my values, but pretty easy.
320 are the two values that I came up with.
You're welcome to come up with whatever values you want.
You don't have to do the same as mine.
Your game should feel the way you want your game to feel.
And that is all for this lecture.
We've added frame rate independence by using time delta time.
I'll see you in the next lecture.