Hello, guys.
In this video, we're going to increase speed of the player every time he reaches a milestone, because
usually in the endless run, the longer you run, the faster your speed until you hit some obstacle.
So this is what we're going to do.
This what makes endless Runner more difficult?
I guess So.
Let's do that.
Let's create a header for speed.
Header speed.
Sorry, speed info.
We're going to need a milestone that we're going to reach.
So it's going to work like this.
Look, we have a player here and we have a milestone.
Once we reach a milestone, we're going to increase speed of the player by some multiplier, and at
the same time we're going to increase milestone as well, because if we'll keep it same, for example,
it was 50.
If we make next 100 because speed of the player is higher now, he will reach 100 faster.
And if we make the next 150, then this milestone will be reached even faster and at some point he'll
reach every milestone so fast we cannot control it.
So what we going to do is not only increase speed of the player but also increase milestone he needs
to reach.
Let's do that.
Let's make serialize field by workload max speed then serialize field, private float speed multiplier
then output a space here so it is pretty than serialize field private float.
We need milestone increase sir, and we need private load speed milestone.
Now let's go below create a function.
Private void.
Speed controller in here.
As I said, we're going to check X of the player, his position if he reached milestone.
So we do this if transform position that x bigger then speed milestone then we can increase speed of
the player of course.
So let's do this move speed multiplied equals speed multiplier.
And if you remember, it is the same as the fuel type move.
Speed equals to move speed multiplied by speed multiplier exactly the same, just different way to write
it.
Maybe for a change we can keep this one.
So we increase speed and we need to increase milestone as well.
We need to do it.
So milestone increase her equals to milestone increase her multiplied by speed multiplier.
Okay.
Now above that let's change milestone itself.
So speed milestone equals to speed milestone plus milestone increase.
So what we're doing here, every time we reach a milestone, we increase this milestone by milestone
increase our we just add a value and this value after that going to be multiplied by speed multiplier.
So every time we add a bigger value, we only need to do a small check here.
We need to make sure our move speed is not bigger than the maximum speed.
So we're going to type.
If move speed bigger than max speed, then more speed equals to max speed.
And maybe let's do a couple of lines here that says if move speed equals to max speed, then return.
So in this way we won't do this check unless our move speed is less than maximum speed.
Okay.
Good enough.
Let's go to update and type here, speed controller.
So we check this function every update.
And last point to mention here, speed milestone by default is zero.
So he'll get his first speed increase meant when he starts the game and that is not okay actually.
So maybe at the start function we can say speed milestone equals to milestone increase for.
Now let's go back to Unity.
We have our speeding four speed multiplier and milestone increase for let's make it 50.
Let's make maximum speed, I don't know, 20 and speed multiplier by how much we're going to make even
faster.
This value will depend on your game design, but I suggest just put something like 1.15 so it's increased
by 15%.
Now I want to go to the platform.
I want to change it so I can see if I am running at all, because when it's the same color, difficult
to know the difference.
Something like this.
Yeah.
Let's hit the play mode.
We can see speed of the player now is 12.
I'm running.
My position.
52 So I reached first milestone and now my speed is 13.8 and milestone increase is 57.
And if I go to debug over here, I can see.
Let me just close this.
I can see that my speed milestone is 100 now.
Let's try this more.
Speed Milestone 157 move speed is 15.8 and milestone increase is 66.
If I go back to normal mode and you remember the value was 157 here.
Normal mode position of the player 108.
So I'm running.
And now it's 154.
When I click on Pause.
My most people be increased.
Yeah 157 reached and I'm faster now and it's working Cool, right?