1
00:00:00,000 --> 00:00:00,000
Hello, guys.

2
00:00:00,000 --> 00:00:02,000
In this video, we're going to make a knockback.

3
00:00:02,000 --> 00:00:04,000
It's going to be pretty simple task.

4
00:00:04,000 --> 00:00:09,000
And first, what we're going to do for this is create animation of knockback.

5
00:00:09,000 --> 00:00:10,000
Let's select our player.

6
00:00:10,000 --> 00:00:16,000
Create new clip assets, animations and player knockback.

7
00:00:18,000 --> 00:00:21,000
Now we don't have knock back animation in the graphics folder.

8
00:00:21,000 --> 00:00:25,000
Actually, we have, but it's kind of different from what we need.

9
00:00:25,000 --> 00:00:29,000
As you can see in this animation, he's falling and then he's standing up.

10
00:00:29,000 --> 00:00:33,000
But we kind of always in the action, we always run in in our game.

11
00:00:33,000 --> 00:00:36,000
So we're going to modify it by just a bit.

12
00:00:36,000 --> 00:00:43,000
I'm going to take my first sprite, drag it here, then second Sprite, drag it here, then third Sprite,

13
00:00:44,000 --> 00:00:50,000
then I'll go to my role animation and I'll take this one.

14
00:00:50,000 --> 00:00:52,000
This looks like he's landing on his back.

15
00:00:53,000 --> 00:00:54,000
Drag it, then this one.

16
00:00:54,000 --> 00:01:00,000
And then from the seventh up to 10th, I guess, just like that.

17
00:01:01,000 --> 00:01:04,000
Now let's put sample rate 12 and see how it looks.

18
00:01:09,000 --> 00:01:10,000
I did something wrong.

19
00:01:10,000 --> 00:01:11,000
Let me see.

20
00:01:11,000 --> 00:01:16,000
So what I want to do is to make impression he's rolling back, and then he's standing up.

21
00:01:16,000 --> 00:01:18,000
So let's delete this.

22
00:01:18,000 --> 00:01:21,000
We have only one, two, three from knock back.

23
00:01:21,000 --> 00:01:24,000
Then first one from him landing on his back.

24
00:01:25,000 --> 00:01:26,000
Let's delete this one.

25
00:01:26,000 --> 00:01:27,000
One, two, three.

26
00:01:27,000 --> 00:01:29,000
And then number six.

27
00:01:30,000 --> 00:01:31,000
Number five.

28
00:01:31,000 --> 00:01:32,000
Like this.

29
00:01:32,000 --> 00:01:33,000
Number four.

30
00:01:33,000 --> 00:01:35,000
Number three.

31
00:01:35,000 --> 00:01:36,000
Number two.

32
00:01:36,000 --> 00:01:38,000
And then number nine.

33
00:01:38,000 --> 00:01:39,000
Yeah.

34
00:01:40,000 --> 00:01:42,000
So it goes like this.

35
00:01:43,000 --> 00:01:46,000
And number ten for standing up.

36
00:01:47,000 --> 00:01:47,000
Let me see.

37
00:01:47,000 --> 00:01:49,000
Now that's more like what we need.

38
00:01:49,000 --> 00:01:53,000
We can see sprites over here if you want to see a precise.

39
00:01:53,000 --> 00:01:55,000
Let's go to animator.

40
00:01:56,000 --> 00:01:57,000
Create bullion.

41
00:01:57,000 --> 00:02:00,000
I'm going to make more space here so we can see it.

42
00:02:04,000 --> 00:02:05,000
Let's create bullion.

43
00:02:06,000 --> 00:02:08,000
Can is knocked.

44
00:02:09,000 --> 00:02:11,000
I'm going to drag it maybe here.

45
00:02:12,000 --> 00:02:19,000
Make transition from any stage to knock back condition is knocked true.

46
00:02:19,000 --> 00:02:22,000
Let me drag it above exit time.

47
00:02:22,000 --> 00:02:30,000
No duration transition Duration zero from knockback transition to idle and exit time here will be just

48
00:02:30,000 --> 00:02:30,000
one.

49
00:02:30,000 --> 00:02:32,000
Duration zero.

50
00:02:34,000 --> 00:02:35,000
We're going to add an event here.

51
00:02:35,000 --> 00:02:38,000
But later for now, let's just go to script.

52
00:02:39,000 --> 00:02:40,000
Oh, wait a second.

53
00:02:40,000 --> 00:02:45,000
We need to go to any state to jump full and add condition here.

54
00:02:46,000 --> 00:02:47,000
Is not should be false.

55
00:02:47,000 --> 00:02:52,000
If we want to go to jump fall, so animation will not be interrupted.

56
00:02:52,000 --> 00:02:53,000
Now let's go to code.

57
00:02:53,000 --> 00:02:55,000
Let's create header.

58
00:02:57,000 --> 00:02:59,000
Knock back info.

59
00:03:00,000 --> 00:03:07,000
Then we're going to create serialized field private vector to knock back direction and private boolean

60
00:03:07,000 --> 00:03:12,000
that tells us if player is knocked or not, so is knocked.

61
00:03:14,000 --> 00:03:16,000
Now let's go to update.

62
00:03:17,000 --> 00:03:21,000
And just here we're going to say if is knocked then return.

63
00:03:22,000 --> 00:03:28,000
So basically it means if player is knocked, we're not going to do any of this functionality.

64
00:03:28,000 --> 00:03:33,000
So we're not changing speed player is not moving, there is no input, nothing.

65
00:03:33,000 --> 00:03:36,000
So we cannot do anything until knockback is over.

66
00:03:36,000 --> 00:03:47,000
Now let's go below the update and make a function private void knockback which will set is knocked to

67
00:03:47,000 --> 00:03:52,000
true and we'll set velocity of the player just wants to direction of the knockback.

68
00:03:52,000 --> 00:03:56,000
So rb dot velocity equals to knockback direction.

69
00:03:58,000 --> 00:04:00,000
Okay, That's good.

70
00:04:01,000 --> 00:04:02,000
Now let's go here and create another function.

71
00:04:02,000 --> 00:04:04,000
Private void.

72
00:04:04,000 --> 00:04:06,000
Knock back.

73
00:04:09,000 --> 00:04:11,000
Cancel knockback.

74
00:04:13,000 --> 00:04:17,000
Which will do only one thing it will set is not to false.

75
00:04:17,000 --> 00:04:20,000
So maybe we can return it as one line.

76
00:04:22,000 --> 00:04:23,000
Just like this.

77
00:04:26,000 --> 00:04:28,000
Now we want to call this knock back somehow.

78
00:04:28,000 --> 00:04:33,000
And later, are we going to do it when player gets hit by a trap or something?

79
00:04:33,000 --> 00:04:35,000
But now we don't have any trap or anything in the game.

80
00:04:35,000 --> 00:04:40,000
I just want to set up knock back first so I'll do short input to make knock back.

81
00:04:40,000 --> 00:04:47,000
So it will be like this input get key down key code dot key K.

82
00:04:47,000 --> 00:04:52,000
So now if I'll press my K on the keyboard he'll be knocked basically.

83
00:04:52,000 --> 00:04:56,000
Then later we're just going to call this function from a trap or anything we need.

84
00:04:57,000 --> 00:04:59,000
Let's go back to Unity.

85
00:05:01,000 --> 00:05:02,000
Find the player.

86
00:05:04,000 --> 00:05:07,000
But let me find the script and we're going to set knock back direction.

87
00:05:07,000 --> 00:05:10,000
Remember, on the X, it should be negative value.

88
00:05:10,000 --> 00:05:16,000
So he goes to the left, I'll try -12 and for the Y, I want to try seven.

89
00:05:16,000 --> 00:05:16,000
Now.

90
00:05:16,000 --> 00:05:18,000
Let's see it in the game.

91
00:05:20,000 --> 00:05:20,000
Okay.

92
00:05:21,000 --> 00:05:22,000
We're running and pressing.

93
00:05:22,000 --> 00:05:23,000
Kay.

94
00:05:23,000 --> 00:05:24,000
Boom!

95
00:05:24,000 --> 00:05:24,000
Knocked.

96
00:05:25,000 --> 00:05:26,000
Okay.

97
00:05:26,000 --> 00:05:27,000
What is wrong with that?

98
00:05:27,000 --> 00:05:29,000
All right, let's do it as a challenge.

99
00:05:29,000 --> 00:05:30,000
Can you figure out what is wrong?

100
00:05:30,000 --> 00:05:32,000
Why knockback didn't work?

101
00:05:32,000 --> 00:05:37,000
I mean, it worked, but there was no animation, so I'm giving you a chance to fix that.

102
00:05:37,000 --> 00:05:40,000
One, two, three.

103
00:05:40,000 --> 00:05:42,000
Okay, let's go back.

104
00:05:42,000 --> 00:05:47,000
Let's go back to code and find our animator controllers and set anim.

105
00:05:47,000 --> 00:05:48,000
Set bool.

106
00:05:49,000 --> 00:05:51,000
Is knocked to.

107
00:05:51,000 --> 00:05:52,000
Is knocked.

108
00:05:52,000 --> 00:05:52,000
Bullion.

109
00:05:55,000 --> 00:05:55,000
Key.

110
00:05:56,000 --> 00:05:59,000
Now we need to find our player animation.

111
00:06:01,000 --> 00:06:08,000
Knock back add in event in the end over here that says cancel knockback.

112
00:06:09,000 --> 00:06:11,000
OC play mode.

113
00:06:15,000 --> 00:06:16,000
I'm running.

114
00:06:16,000 --> 00:06:17,000
I'll press.

115
00:06:17,000 --> 00:06:18,000
Kay.

116
00:06:18,000 --> 00:06:19,000
Boom.

117
00:06:19,000 --> 00:06:20,000
Knocked.

118
00:06:21,000 --> 00:06:22,000
Kay.

119
00:06:22,000 --> 00:06:23,000
That is my fault.

120
00:06:23,000 --> 00:06:28,000
This is what happens if you don't touch this checkbox.

121
00:06:28,000 --> 00:06:30,000
Can transmit to self.

122
00:06:30,000 --> 00:06:31,000
We need to uncheck this.

123
00:06:31,000 --> 00:06:34,000
We need to make sure we are in check in transit to self.

124
00:06:36,000 --> 00:06:41,000
Now, you know, if your animation freezes on the first frame and check and transit to self.

125
00:06:42,000 --> 00:06:43,000
Right.

126
00:06:43,000 --> 00:06:44,000
Boom.

127
00:06:44,000 --> 00:06:44,000
Knocked.

128
00:06:45,000 --> 00:06:47,000
This looks pretty good, right?

129
00:06:54,000 --> 00:06:57,000
We can make his floating animation a bit longer.

130
00:06:57,000 --> 00:06:59,000
That I'll go to animation of the knockback.

131
00:07:03,000 --> 00:07:04,000
Where is the floating animation?

132
00:07:04,000 --> 00:07:05,000
This one.

133
00:07:05,000 --> 00:07:10,000
And I'll take all of the frames and I'll just move them to the right by one frame.

134
00:07:10,000 --> 00:07:12,000
And I need to move this event now, like this.

135
00:07:12,000 --> 00:07:16,000
So now this frame will be played for two frames.

136
00:07:19,000 --> 00:07:21,000
Yeah, I think that's better.

137
00:07:23,000 --> 00:07:27,000
If you want to change something, you can change speed of the animation, for example.

138
00:07:27,000 --> 00:07:28,000
Now let me find it.

139
00:07:28,000 --> 00:07:32,000
Knock back change sample rate to 15.

140
00:07:33,000 --> 00:07:35,000
Then he'll do it faster.

141
00:07:35,000 --> 00:07:35,000
Boom.

142
00:07:37,000 --> 00:07:42,000
If you want to change strengths of the knock back its power, you can change knockback direction.

143
00:07:42,000 --> 00:07:46,000
So more on the X like -20.

144
00:07:46,000 --> 00:07:50,000
He'll get pushed further just like that.

145
00:07:51,000 --> 00:07:55,000
Or if you put higher y he'll he'll be knocked higher.

146
00:08:00,000 --> 00:08:02,000
But I think I chose pretty good values.

147
00:08:02,000 --> 00:08:04,000
-12 and seven.

148
00:08:04,000 --> 00:08:05,000
Okay, very good.

149
00:08:05,000 --> 00:08:06,000
Let's go to the next video.

