1
00:00:00,000 --> 00:00:00,000
Hello, guys.

2
00:00:00,000 --> 00:00:05,000
In this video, we're going to increase speed of the player every time he reaches a milestone, because

3
00:00:05,000 --> 00:00:11,000
usually in the endless run, the longer you run, the faster your speed until you hit some obstacle.

4
00:00:11,000 --> 00:00:12,000
So this is what we're going to do.

5
00:00:12,000 --> 00:00:15,000
This what makes endless Runner more difficult?

6
00:00:15,000 --> 00:00:16,000
I guess So.

7
00:00:16,000 --> 00:00:16,000
Let's do that.

8
00:00:16,000 --> 00:00:19,000
Let's create a header for speed.

9
00:00:19,000 --> 00:00:20,000
Header speed.

10
00:00:20,000 --> 00:00:22,000
Sorry, speed info.

11
00:00:24,000 --> 00:00:26,000
We're going to need a milestone that we're going to reach.

12
00:00:26,000 --> 00:00:28,000
So it's going to work like this.

13
00:00:28,000 --> 00:00:34,000
Look, we have a player here and we have a milestone.

14
00:00:35,000 --> 00:00:41,000
Once we reach a milestone, we're going to increase speed of the player by some multiplier, and at

15
00:00:41,000 --> 00:00:46,000
the same time we're going to increase milestone as well, because if we'll keep it same, for example,

16
00:00:46,000 --> 00:00:47,000
it was 50.

17
00:00:48,000 --> 00:00:55,000
If we make next 100 because speed of the player is higher now, he will reach 100 faster.

18
00:00:55,000 --> 00:01:04,000
And if we make the next 150, then this milestone will be reached even faster and at some point he'll

19
00:01:04,000 --> 00:01:07,000
reach every milestone so fast we cannot control it.

20
00:01:07,000 --> 00:01:12,000
So what we going to do is not only increase speed of the player but also increase milestone he needs

21
00:01:12,000 --> 00:01:12,000
to reach.

22
00:01:12,000 --> 00:01:13,000
Let's do that.

23
00:01:13,000 --> 00:01:24,000
Let's make serialize field by workload max speed then serialize field, private float speed multiplier

24
00:01:24,000 --> 00:01:30,000
then output a space here so it is pretty than serialize field private float.

25
00:01:30,000 --> 00:01:38,000
We need milestone increase sir, and we need private load speed milestone.

26
00:01:38,000 --> 00:01:41,000
Now let's go below create a function.

27
00:01:42,000 --> 00:01:43,000
Private void.

28
00:01:43,000 --> 00:01:47,000
Speed controller in here.

29
00:01:47,000 --> 00:01:51,000
As I said, we're going to check X of the player, his position if he reached milestone.

30
00:01:51,000 --> 00:02:00,000
So we do this if transform position that x bigger then speed milestone then we can increase speed of

31
00:02:00,000 --> 00:02:01,000
the player of course.

32
00:02:01,000 --> 00:02:06,000
So let's do this move speed multiplied equals speed multiplier.

33
00:02:07,000 --> 00:02:10,000
And if you remember, it is the same as the fuel type move.

34
00:02:10,000 --> 00:02:17,000
Speed equals to move speed multiplied by speed multiplier exactly the same, just different way to write

35
00:02:17,000 --> 00:02:17,000
it.

36
00:02:18,000 --> 00:02:20,000
Maybe for a change we can keep this one.

37
00:02:20,000 --> 00:02:25,000
So we increase speed and we need to increase milestone as well.

38
00:02:25,000 --> 00:02:26,000
We need to do it.

39
00:02:26,000 --> 00:02:33,000
So milestone increase her equals to milestone increase her multiplied by speed multiplier.

40
00:02:33,000 --> 00:02:34,000
Okay.

41
00:02:34,000 --> 00:02:36,000
Now above that let's change milestone itself.

42
00:02:36,000 --> 00:02:41,000
So speed milestone equals to speed milestone plus milestone increase.

43
00:02:42,000 --> 00:02:48,000
So what we're doing here, every time we reach a milestone, we increase this milestone by milestone

44
00:02:48,000 --> 00:02:55,000
increase our we just add a value and this value after that going to be multiplied by speed multiplier.

45
00:02:55,000 --> 00:03:00,000
So every time we add a bigger value, we only need to do a small check here.

46
00:03:00,000 --> 00:03:04,000
We need to make sure our move speed is not bigger than the maximum speed.

47
00:03:04,000 --> 00:03:05,000
So we're going to type.

48
00:03:05,000 --> 00:03:10,000
If move speed bigger than max speed, then more speed equals to max speed.

49
00:03:10,000 --> 00:03:19,000
And maybe let's do a couple of lines here that says if move speed equals to max speed, then return.

50
00:03:19,000 --> 00:03:25,000
So in this way we won't do this check unless our move speed is less than maximum speed.

51
00:03:27,000 --> 00:03:27,000
Okay.

52
00:03:27,000 --> 00:03:28,000
Good enough.

53
00:03:28,000 --> 00:03:32,000
Let's go to update and type here, speed controller.

54
00:03:33,000 --> 00:03:36,000
So we check this function every update.

55
00:03:36,000 --> 00:03:40,000
And last point to mention here, speed milestone by default is zero.

56
00:03:40,000 --> 00:03:46,000
So he'll get his first speed increase meant when he starts the game and that is not okay actually.

57
00:03:46,000 --> 00:03:52,000
So maybe at the start function we can say speed milestone equals to milestone increase for.

58
00:03:53,000 --> 00:03:55,000
Now let's go back to Unity.

59
00:03:55,000 --> 00:04:00,000
We have our speeding four speed multiplier and milestone increase for let's make it 50.

60
00:04:01,000 --> 00:04:07,000
Let's make maximum speed, I don't know, 20 and speed multiplier by how much we're going to make even

61
00:04:07,000 --> 00:04:08,000
faster.

62
00:04:08,000 --> 00:04:14,000
This value will depend on your game design, but I suggest just put something like 1.15 so it's increased

63
00:04:14,000 --> 00:04:16,000
by 15%.

64
00:04:16,000 --> 00:04:18,000
Now I want to go to the platform.

65
00:04:18,000 --> 00:04:24,000
I want to change it so I can see if I am running at all, because when it's the same color, difficult

66
00:04:24,000 --> 00:04:25,000
to know the difference.

67
00:04:25,000 --> 00:04:27,000
Something like this.

68
00:04:27,000 --> 00:04:28,000
Yeah.

69
00:04:28,000 --> 00:04:29,000
Let's hit the play mode.

70
00:04:29,000 --> 00:04:32,000
We can see speed of the player now is 12.

71
00:04:32,000 --> 00:04:33,000
I'm running.

72
00:04:37,000 --> 00:04:37,000
My position.

73
00:04:37,000 --> 00:04:47,000
52 So I reached first milestone and now my speed is 13.8 and milestone increase is 57.

74
00:04:48,000 --> 00:04:51,000
And if I go to debug over here, I can see.

75
00:04:51,000 --> 00:04:53,000
Let me just close this.

76
00:04:54,000 --> 00:04:57,000
I can see that my speed milestone is 100 now.

77
00:04:59,000 --> 00:05:01,000
Let's try this more.

78
00:05:06,000 --> 00:05:14,000
Speed Milestone 157 move speed is 15.8 and milestone increase is 66.

79
00:05:14,000 --> 00:05:19,000
If I go back to normal mode and you remember the value was 157 here.

80
00:05:20,000 --> 00:05:23,000
Normal mode position of the player 108.

81
00:05:24,000 --> 00:05:25,000
So I'm running.

82
00:05:30,000 --> 00:05:32,000
And now it's 154.

83
00:05:32,000 --> 00:05:34,000
When I click on Pause.

84
00:05:34,000 --> 00:05:36,000
My most people be increased.

85
00:05:37,000 --> 00:05:42,000
Yeah 157 reached and I'm faster now and it's working Cool, right?

