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 make slide ability, and I want to start doing that by actually creating

3
00:00:05,000 --> 00:00:06,000
an animation for this.

4
00:00:06,000 --> 00:00:07,000
Right.

5
00:00:07,000 --> 00:00:08,000
Going to be easy to do.

6
00:00:09,000 --> 00:00:15,000
All what we need is to select the player, click animation, create new clip player.

7
00:00:15,000 --> 00:00:17,000
It'll none of it player slide.

8
00:00:17,000 --> 00:00:18,000
Right.

9
00:00:18,000 --> 00:00:22,000
Then let's go to graphics player find.

10
00:00:23,000 --> 00:00:27,000
Slide and drag sprites over here.

11
00:00:28,000 --> 00:00:30,000
Let's check the speed of the sprites.

12
00:00:30,000 --> 00:00:33,000
Going to be 15, I guess is fine.

13
00:00:33,000 --> 00:00:35,000
I guess this looks fine.

14
00:00:35,000 --> 00:00:35,000
Okay.

15
00:00:35,000 --> 00:00:39,000
Let's go to animator now, and let's think about this first.

16
00:00:39,000 --> 00:00:41,000
We need to condition that we're going to use.

17
00:00:42,000 --> 00:00:45,000
And there's going to be a bullion.

18
00:00:46,000 --> 00:00:47,000
Is sliding.

19
00:00:47,000 --> 00:00:49,000
Let's move it above over here.

20
00:00:50,000 --> 00:00:54,000
And next step is to know when we do in transition to slide.

21
00:00:54,000 --> 00:00:58,000
If you think about this, you're going to do slide from the air from jump or double jump.

22
00:00:58,000 --> 00:01:00,000
It should be on the ground.

23
00:01:00,000 --> 00:01:02,000
So let's do this from the move state.

24
00:01:02,000 --> 00:01:05,000
Let's make a transition to play or slide.

25
00:01:06,000 --> 00:01:11,000
With the condition is slight in true and check exit time and duration should be zero.

26
00:01:13,000 --> 00:01:15,000
Now let's make another transition back.

27
00:01:17,000 --> 00:01:22,000
A slide in false duration zero and check exit time.

28
00:01:23,000 --> 00:01:24,000
That's good enough.

29
00:01:24,000 --> 00:01:27,000
Now let's go to the script of the player to make a slide.

30
00:01:27,000 --> 00:01:29,000
We're going to use a timer.

31
00:01:29,000 --> 00:01:30,000
How We can use a timer.

32
00:01:30,000 --> 00:01:33,000
I'm going to explain first and then we're going to make slide itself.

33
00:01:33,000 --> 00:01:37,000
Let me create a public variable over here, public float timer.

34
00:01:37,000 --> 00:01:46,000
Then I'll go to update and I'll type timer equals to timer minus time, dot delta time.

35
00:01:46,000 --> 00:01:54,000
So time, dot delta time is a time that was taken to go from the last frame to current one and basically

36
00:01:54,000 --> 00:01:56,000
just to make it simple to understand.

37
00:01:56,000 --> 00:02:02,000
And so we can use it, we use time dot, delta time whenever we need to count time in seconds.

38
00:02:02,000 --> 00:02:07,000
As you can see here, now we're taking our float time and doing minus time, dot, delta time, every

39
00:02:07,000 --> 00:02:08,000
update.

40
00:02:08,000 --> 00:02:15,000
So right now, if I go to my unity and I'll go to play mode, you can see that my timer decreasing all

41
00:02:15,000 --> 00:02:15,000
the time.

42
00:02:15,000 --> 00:02:20,000
It goes to minus three, minus four, minus five and so on, basically like a seconds.

43
00:02:20,000 --> 00:02:23,000
And we're going to use this timer to make a slight ability.

44
00:02:23,000 --> 00:02:30,000
Basically what we're going to do is to make that player can slide if timer more than zero.

45
00:02:30,000 --> 00:02:35,000
And at the same time we're going to give timer the value of 2 seconds and it's going to decrease itself.

46
00:02:35,000 --> 00:02:39,000
And when it will be below the zero slide, the ability will be stopped.

47
00:02:39,000 --> 00:02:40,000
This how it's going to work.

48
00:02:40,000 --> 00:02:46,000
I know time dot delta time might be confusing at first, but believe me, with the time it will be easier

49
00:02:46,000 --> 00:02:53,000
to understand and it's going to be just a very comfortable tool that you use for cooldowns and some

50
00:02:53,000 --> 00:02:55,000
ability that takes time and so on.

51
00:02:55,000 --> 00:02:57,000
So let's just try and practice.

52
00:02:57,000 --> 00:02:57,000
All right?

53
00:02:58,000 --> 00:03:03,000
I'm going to delete this and we can delete this one as well.

54
00:03:04,000 --> 00:03:05,000
And I'm going to create a Heather.

55
00:03:07,000 --> 00:03:09,000
Slide info.

56
00:03:09,000 --> 00:03:10,000
Now, what do we need for a slide?

57
00:03:11,000 --> 00:03:12,000
First we need the speed.

58
00:03:12,000 --> 00:03:16,000
So serialize field, private float, slide, speed.

59
00:03:17,000 --> 00:03:19,000
Then we need time.

60
00:03:19,000 --> 00:03:21,000
How long are we going to slide?

61
00:03:21,000 --> 00:03:27,000
Let's do serialize field, private float, slide time and we need a counter that we're going to use

62
00:03:27,000 --> 00:03:29,000
to check how long we slide in.

63
00:03:29,000 --> 00:03:34,000
So private float, slide time counter.

64
00:03:34,000 --> 00:03:37,000
And this the value we're going to decrease with the time.

65
00:03:39,000 --> 00:03:46,000
Also, we need the boolean to know if we are sliding at the moment, so private ball is sliding.

66
00:03:47,000 --> 00:03:48,000
Cool.

67
00:03:48,000 --> 00:03:49,000
I'm going to save it.

68
00:03:49,000 --> 00:03:56,000
Go to update and before you've seen I typed something like this slide time counter equals to slide time

69
00:03:56,000 --> 00:04:00,000
counter minus time, the delta time.

70
00:04:00,000 --> 00:04:07,000
But this looks kind of long and we can make it shorter if you will type slide time counter minus equals

71
00:04:07,000 --> 00:04:11,000
time to time it would actually mean the same.

72
00:04:11,000 --> 00:04:14,000
These two lines mean totally the same.

73
00:04:14,000 --> 00:04:20,000
They just written differently and you are allowed to use whatever way you like, but I think it's best

74
00:04:20,000 --> 00:04:23,000
to keep it cleaner and lighter.

75
00:04:23,000 --> 00:04:25,000
So I'll keep this option.

76
00:04:25,000 --> 00:04:31,000
Now we're going to go to check input over here, go to definition, and we're going to type here if

77
00:04:31,000 --> 00:04:35,000
input and I don't remember if there is a button for slide.

78
00:04:35,000 --> 00:04:39,000
So I want to use get key this time, but we can change it later if we need to.

79
00:04:40,000 --> 00:04:41,000
So get key down.

80
00:04:43,000 --> 00:04:47,000
Key down echoed left shift.

81
00:04:48,000 --> 00:04:51,000
And if this was pressed, then we make a sliding.

82
00:04:52,000 --> 00:04:53,000
True.

83
00:04:54,000 --> 00:04:56,000
Now let's think about this.

84
00:04:56,000 --> 00:04:59,000
What we can have with this value is slight and true.

85
00:04:59,000 --> 00:05:03,000
First, we can set an animator, and let's do it here.

86
00:05:04,000 --> 00:05:08,000
And I actually want to change the look of it a bit, said Bull.

87
00:05:10,000 --> 00:05:14,000
Is sliding to a sliding now animator set.

88
00:05:14,000 --> 00:05:17,000
And let me move these two lines of code above.

89
00:05:20,000 --> 00:05:23,000
So we're going to have section for float and for bullion.

90
00:05:24,000 --> 00:05:24,000
Yeah.

91
00:05:24,000 --> 00:05:27,000
Now, when we press shift, we set a slide in.

92
00:05:27,000 --> 00:05:33,000
True animator is on and now we need to change speed of the character as well.

93
00:05:33,000 --> 00:05:36,000
So let's go to movement over here and type.

94
00:05:36,000 --> 00:05:46,000
If is sliding then RB velocity equals to a new vector two is going to be slight speed this time and

95
00:05:46,000 --> 00:05:47,000
we're not going to change y.

96
00:05:48,000 --> 00:05:49,000
Else.

97
00:05:49,000 --> 00:05:53,000
If it's not sliding, then regular velocity like we are running.

98
00:05:53,000 --> 00:05:57,000
If we're going to run it like that, it's going to work and we're going to enter the slide state, but

99
00:05:57,000 --> 00:06:00,000
we're never going to exit the slide state.

100
00:06:00,000 --> 00:06:05,000
Let me just select the player and change his velocity of the slide.

101
00:06:06,000 --> 00:06:07,000
Player.

102
00:06:07,000 --> 00:06:10,000
Slide speed to, let's say, 15.

103
00:06:10,000 --> 00:06:15,000
Now, if I'll run, I'm in the slide, but I'm not exiting the slide.

104
00:06:15,000 --> 00:06:16,000
It's going to work endlessly.

105
00:06:16,000 --> 00:06:19,000
So we need to make a condition to exit the slide.

106
00:06:19,000 --> 00:06:20,000
How are we going to do it?

107
00:06:20,000 --> 00:06:27,000
We're going to go back to code, create a function that we're going to call, check or slide.

108
00:06:27,000 --> 00:06:31,000
And let's click alt enter generate method.

109
00:06:32,000 --> 00:06:36,000
And inside of this check slide, we're going to do this.

110
00:06:36,000 --> 00:06:43,000
If slide time counter less than zero, then we're going to set a sliding pulse.

111
00:06:44,000 --> 00:06:45,000
All right.

112
00:06:46,000 --> 00:06:49,000
Now we need to set a counter when we're pressing the button.

113
00:06:49,000 --> 00:06:55,000
And actually, it's going to do a lot more than that, not only set in slide into true and set the counter.

114
00:06:55,000 --> 00:06:58,000
So we better create a method for this one as well.

115
00:06:58,000 --> 00:07:06,000
Let's select the line, click alt, enter, extract method and we're going to call it slide button and

116
00:07:06,000 --> 00:07:08,000
inside we're going to do is slide in.

117
00:07:08,000 --> 00:07:08,000
True.

118
00:07:09,000 --> 00:07:12,000
And we're going to set slide time counter.

119
00:07:12,000 --> 00:07:17,000
Equals two slide time wines named slide timer.

120
00:07:17,000 --> 00:07:19,000
Okay, let's press control.

121
00:07:19,000 --> 00:07:20,000
RR.

122
00:07:21,000 --> 00:07:22,000
And type here.

123
00:07:22,000 --> 00:07:24,000
Slide time.

124
00:07:25,000 --> 00:07:26,000
And here as well.

125
00:07:27,000 --> 00:07:27,000
Slide.

126
00:07:27,000 --> 00:07:29,000
Time counter.

127
00:07:30,000 --> 00:07:31,000
Okay.

128
00:07:33,000 --> 00:07:34,000
This is done?

129
00:07:34,000 --> 00:07:35,000
I guess it is done.

130
00:07:35,000 --> 00:07:36,000
Yeah.

131
00:07:39,000 --> 00:07:40,000
Let me see.

132
00:07:41,000 --> 00:07:43,000
We actually want to make sure it's working.

133
00:07:43,000 --> 00:07:44,000
So let's go and do this.

134
00:07:45,000 --> 00:07:51,000
I need to set slide time so it's going to be point four and slide speed going to be.

135
00:07:51,000 --> 00:07:52,000
Let's try.

136
00:07:54,000 --> 00:07:54,000
20.

137
00:07:56,000 --> 00:07:57,000
Okay, let's go now.

138
00:08:05,000 --> 00:08:08,000
And we don't slide and going back.

139
00:08:10,000 --> 00:08:13,000
We get in faster and going back to running.

140
00:08:13,000 --> 00:08:14,000
Running.

141
00:08:18,000 --> 00:08:18,000
Perfect.

142
00:08:18,000 --> 00:08:21,000
Now, there are a couple of issues here.

143
00:08:21,000 --> 00:08:26,000
First is if I place any role in front of the character.

144
00:08:30,000 --> 00:08:31,000
Like this.

145
00:08:32,000 --> 00:08:34,000
First, I cannot enter the slide.

146
00:08:35,000 --> 00:08:37,000
I can enter the animation, but I cannot move.

147
00:08:37,000 --> 00:08:40,000
Because if you remember, we restrict movement.

148
00:08:40,000 --> 00:08:46,000
If there is a wall detected and that is absolutely correct behavior, in my opinion, you should not

149
00:08:46,000 --> 00:08:48,000
be able to do slide if you are standing.

150
00:08:48,000 --> 00:08:52,000
So it's kind of like a gameplay decision, I would say.

151
00:08:52,000 --> 00:08:59,000
So if you did not jump over the wall or if you did not do slide under the platform, it means you made

152
00:08:59,000 --> 00:09:00,000
a mistake.

153
00:09:00,000 --> 00:09:03,000
And for that you are paying with your time and speed.

154
00:09:04,000 --> 00:09:08,000
So we need to jump over the platform and get your speed again.

155
00:09:08,000 --> 00:09:15,000
So that's why what we're going to do here is to make sure you can enter slide only if you have velocity

156
00:09:15,000 --> 00:09:16,000
on the X.

157
00:09:16,000 --> 00:09:19,000
So we go to slide button over here and type.

158
00:09:19,000 --> 00:09:25,000
If RB velocity dot x not equals to zero, then we do these two.

159
00:09:26,000 --> 00:09:27,000
Just like that.

160
00:09:28,000 --> 00:09:33,000
Yes, So I can do slide, but if I will lose my speed for some reason.

161
00:09:38,000 --> 00:09:38,000
Next.

162
00:09:38,000 --> 00:09:38,000
So.

163
00:09:40,000 --> 00:09:45,000
Then I have to jump over and try it again and try again.

164
00:09:46,000 --> 00:09:47,000
All right.

165
00:09:47,000 --> 00:09:48,000
I guess that's it for this video.

166
00:09:48,000 --> 00:09:49,000
We have work in slide.

167
00:09:49,000 --> 00:09:54,000
We still have things we need to fix with the slide and make it better.

168
00:09:54,000 --> 00:09:57,000
We still have things to improve, so let's move on.

