1
00:00:00,000 --> 00:00:00,000
Hello, guys.

2
00:00:01,000 --> 00:00:06,000
Currently in the game, we have an issue that we need to fix and it will be a target of this video.

3
00:00:06,000 --> 00:00:12,000
So at the moment, if I'll take my platform and turn it into a wall just like that and place it somewhere

4
00:00:12,000 --> 00:00:18,000
in front of character and then I'll run, we can see that when facing the wall, he's doing transition

5
00:00:18,000 --> 00:00:24,000
between idle and move animation endlessly, and it looks like a bug, but it's not like a bug.

6
00:00:24,000 --> 00:00:29,000
It's more of a misbehavior I would say that we did not fix yet, so this would be going to do how we

7
00:00:29,000 --> 00:00:30,000
can fix it.

8
00:00:30,000 --> 00:00:35,000
We could just check if there is anything in front of the character and if there is, then we're going

9
00:00:35,000 --> 00:00:36,000
to stop.

10
00:00:36,000 --> 00:00:40,000
Or if to be more precise, we're not going to move anymore.

11
00:00:40,000 --> 00:00:40,000
All right.

12
00:00:40,000 --> 00:00:41,000
How we can do that?

13
00:00:41,000 --> 00:00:45,000
We could do it with a check saying what we did for the ground.

14
00:00:45,000 --> 00:00:46,000
Check this one.

15
00:00:46,000 --> 00:00:48,000
You remember this check?

16
00:00:48,000 --> 00:00:54,000
We could make another check from the head of the player, let's say, to the right side to see if there

17
00:00:54,000 --> 00:00:55,000
is a wall.

18
00:00:55,000 --> 00:00:57,000
But that leaves us with an issue.

19
00:00:57,000 --> 00:01:03,000
What if we face in not a wall like that, but a platform about half the size of the player?

20
00:01:03,000 --> 00:01:08,000
And if check is like that and there is still something, you're going to keep running like that.

21
00:01:09,000 --> 00:01:13,000
Okay, We could make another check from the feet of the player just like that.

22
00:01:13,000 --> 00:01:16,000
So at this point we would detect the platform.

23
00:01:16,000 --> 00:01:22,000
But what if what if it would be a very slim platform, let's say a platform of this size?

24
00:01:22,000 --> 00:01:24,000
And we have a check from his head, from his feet.

25
00:01:24,000 --> 00:01:24,000
So now what?

26
00:01:24,000 --> 00:01:26,000
We need to make another check from here.

27
00:01:26,000 --> 00:01:29,000
Then again, then again, then again, then again.

28
00:01:29,000 --> 00:01:33,000
And at this point, you can see it's kind of look like a box in front of the character.

29
00:01:33,000 --> 00:01:39,000
So what we can do is to use box cast to check if there is in front of the check, if there is anything

30
00:01:39,000 --> 00:01:40,000
in front of us.

31
00:01:40,000 --> 00:01:45,000
Basically, we're going to draw a box of somewhat this size.

32
00:01:45,000 --> 00:01:49,000
And if any wheel gets into this box, then we're going to stop movement.

33
00:01:49,000 --> 00:01:51,000
All right, let's do that.

34
00:01:51,000 --> 00:01:53,000
And I want to begin with simple.

35
00:01:53,000 --> 00:01:57,000
I want to draw that box with the gizmos, and then we're going to set the logic.

36
00:01:57,000 --> 00:01:57,000
All right.

37
00:01:58,000 --> 00:01:59,000
What do we need to do?

38
00:01:59,000 --> 00:02:08,000
Let's go to gizmos over here, type gizmos, draw a wire cube and you can see we need a center and we

39
00:02:08,000 --> 00:02:10,000
need a size of the box.

40
00:02:10,000 --> 00:02:19,000
So we're going above to collision info over here, creating serialized field private transform.

41
00:02:19,000 --> 00:02:21,000
That's going to be a center position for the box.

42
00:02:21,000 --> 00:02:24,000
So we'll check, I'll name it, we'll check.

43
00:02:24,000 --> 00:02:28,000
And we need the size and we're not working in 3D, as you remember.

44
00:02:28,000 --> 00:02:32,000
We work in into this space so we can use vector two for the size of the box.

45
00:02:32,000 --> 00:02:34,000
We'll check size.

46
00:02:35,000 --> 00:02:35,000
All right.

47
00:02:36,000 --> 00:02:38,000
And while we are here, let's create a boolean.

48
00:02:40,000 --> 00:02:42,000
Well, sorry.

49
00:02:42,000 --> 00:02:44,000
Well, Detective.

50
00:02:45,000 --> 00:02:46,000
Okay.

51
00:02:48,000 --> 00:02:50,000
Now let's go all the way down.

52
00:02:50,000 --> 00:02:52,000
And here we're going to type.

53
00:02:53,000 --> 00:02:56,000
We'll check that position.

54
00:02:56,000 --> 00:02:58,000
And for the size, we'll check size.

55
00:02:59,000 --> 00:03:00,000
Now let's go back to Unity.

56
00:03:00,000 --> 00:03:04,000
Oh, and sorry, I had this object from testing, but don't worry.

57
00:03:04,000 --> 00:03:05,000
I'm going to show you how to make it.

58
00:03:05,000 --> 00:03:10,000
So let's create an empty under the player and just name it as well.

59
00:03:10,000 --> 00:03:10,000
Check.

60
00:03:11,000 --> 00:03:15,000
All right, Now we're going to select the player and drag ball check to this field.

61
00:03:17,000 --> 00:03:20,000
Now let's set the world check size to 1 to 1.

62
00:03:21,000 --> 00:03:22,000
And by dragging this wall.

63
00:03:22,000 --> 00:03:24,000
Check this one.

64
00:03:25,000 --> 00:03:25,000
Sorry.

65
00:03:26,000 --> 00:03:28,000
We can place it somewhere.

66
00:03:28,000 --> 00:03:35,000
And now if we move a player, it will move together with a player because it is child of the player

67
00:03:35,000 --> 00:03:36,000
and player.

68
00:03:36,000 --> 00:03:36,000
It's parent.

69
00:03:36,000 --> 00:03:41,000
So it kind of has this position, right, no matter how he moves.

70
00:03:42,000 --> 00:03:44,000
Now when adjust the size of it.

71
00:03:44,000 --> 00:03:52,000
So we don't need it so wide because if it's going to be very wide, let's say of this size, then layer

72
00:03:52,000 --> 00:03:55,000
will detect all and this point.

73
00:03:55,000 --> 00:03:55,000
Right.

74
00:03:55,000 --> 00:04:01,000
And he'll stop and there will be empty space between him and the wall, not what we need so we can make

75
00:04:01,000 --> 00:04:02,000
it slim.

76
00:04:02,000 --> 00:04:04,000
Something like 0.5.

77
00:04:04,000 --> 00:04:10,000
And regarding the height, let's try it two and we need to make sure it's above ground level.

78
00:04:10,000 --> 00:04:13,000
So maybe somewhere here I go.

79
00:04:13,000 --> 00:04:15,000
Should we make it higher?

80
00:04:17,000 --> 00:04:21,000
Let's make it 2.25 and place it here.

81
00:04:21,000 --> 00:04:24,000
And later, if we need, we can always fix it.

82
00:04:25,000 --> 00:04:28,000
But now I just want to make sure it's not detected in the ground.

83
00:04:31,000 --> 00:04:32,000
Let's go there.

84
00:04:32,000 --> 00:04:34,000
And it does not.

85
00:04:34,000 --> 00:04:35,000
It is above the ground, right?

86
00:04:36,000 --> 00:04:36,000
Yeah.

87
00:04:36,000 --> 00:04:38,000
By the way, a player is also above the ground.

88
00:04:38,000 --> 00:04:39,000
Why is that?

89
00:04:40,000 --> 00:04:42,000
Because of the collider.

90
00:04:43,000 --> 00:04:44,000
Actually, it's not a big deal, right?

91
00:04:44,000 --> 00:04:46,000
It's not noticeable, but I'll try to.

92
00:04:48,000 --> 00:04:50,000
Yeah, it's better.

93
00:04:51,000 --> 00:04:53,000
Pixel perfect, I would say.

94
00:04:53,000 --> 00:04:55,000
But now my offset and size is messed up.

95
00:04:57,000 --> 00:05:00,000
So point nine here and two point.

96
00:05:02,000 --> 00:05:04,000
Point 4 to 7 of the height.

97
00:05:04,000 --> 00:05:04,000
Yeah.

98
00:05:04,000 --> 00:05:05,000
Let's do this.

99
00:05:07,000 --> 00:05:11,000
Zero nine and 2.2.427.

100
00:05:12,000 --> 00:05:15,000
Here I changed the size and offset the bit here.

101
00:05:17,000 --> 00:05:18,000
To make it precise.

102
00:05:18,000 --> 00:05:20,000
Okay, back to business.

103
00:05:20,000 --> 00:05:26,000
Let's go to player now and in the check collision here we're going to do all detected equals to physics

104
00:05:26,000 --> 00:05:29,000
to DX and guess what we need here?

105
00:05:29,000 --> 00:05:30,000
Box cast.

106
00:05:30,000 --> 00:05:34,000
Now you can see what it requires to work.

107
00:05:34,000 --> 00:05:42,000
We need origin, size, angle, direction, and it's going to be easy to set up.

108
00:05:42,000 --> 00:05:48,000
Let's do origin world check dot position for the size world check size.

109
00:05:49,000 --> 00:05:50,000
Now?

110
00:05:50,000 --> 00:05:51,000
ENGEL We don't need to change it.

111
00:05:51,000 --> 00:05:53,000
So zero direction.

112
00:05:53,000 --> 00:05:54,000
We don't need to change it.

113
00:05:54,000 --> 00:05:54,000
So.

114
00:05:54,000 --> 00:05:57,000
Vector 2.0.

115
00:05:58,000 --> 00:05:59,000
Distance zero.

116
00:05:59,000 --> 00:06:01,000
And now layer mask.

117
00:06:01,000 --> 00:06:02,000
What is ground?

118
00:06:05,000 --> 00:06:06,000
We have that.

119
00:06:06,000 --> 00:06:14,000
Now let's go to player unlocked and just make another condition here and not well detected.

120
00:06:14,000 --> 00:06:19,000
So this movement will be applied if player unlocked and there is no will detect it.

121
00:06:19,000 --> 00:06:21,000
Very simple to do very efficient.

122
00:06:21,000 --> 00:06:23,000
Let's go and see this in the action.

123
00:06:23,000 --> 00:06:26,000
Take the platform and place it in front.

124
00:06:27,000 --> 00:06:28,000
Somewhere.

125
00:06:29,000 --> 00:06:29,000
Somewhere.

126
00:06:29,000 --> 00:06:31,000
And I'll try to face it.

127
00:06:31,000 --> 00:06:31,000
Boom!

128
00:06:31,000 --> 00:06:32,000
Stopped.

129
00:06:34,000 --> 00:06:37,000
If I'll try another one this summer.

130
00:06:37,000 --> 00:06:38,000
Lower.

131
00:06:40,000 --> 00:06:41,000
Stopped.

132
00:06:41,000 --> 00:06:46,000
For now we have a slight issue that we need to fix and.

133
00:06:47,000 --> 00:06:49,000
I'm going to show you what I mean right now.

134
00:06:51,000 --> 00:06:57,000
So look, if I'll go to jump State and I'll do double jump.

135
00:06:58,000 --> 00:07:00,000
Now, Michael, double jump is false.

136
00:07:00,000 --> 00:07:07,000
And if you remember, we're making it true only at the moment of jump from the ground over here.

137
00:07:07,000 --> 00:07:08,000
Right.

138
00:07:09,000 --> 00:07:13,000
And because of that, we cannot transfer to jump full state.

139
00:07:14,000 --> 00:07:21,000
And because of that, when I'm going off the platform without pressing jump, you can see I'm still

140
00:07:21,000 --> 00:07:24,000
doing it in the idle mode state.

141
00:07:24,000 --> 00:07:27,000
I am working on the air.

142
00:07:27,000 --> 00:07:31,000
We have an easy fix for this and I don't see the reason not to use it now.

143
00:07:31,000 --> 00:07:33,000
If we need to change it later, we always can do it.

144
00:07:33,000 --> 00:07:35,000
But for now I'm just going to cut out.

145
00:07:35,000 --> 00:07:37,000
Can double jump through from here.

146
00:07:38,000 --> 00:07:40,000
And I'm going to go to update.

147
00:07:41,000 --> 00:07:43,000
And just like if is grounded.

148
00:07:45,000 --> 00:07:47,000
Then can double jump through.

149
00:07:48,000 --> 00:07:48,000
That's it.

150
00:07:49,000 --> 00:07:51,000
Now let's go and see if it works.

151
00:07:52,000 --> 00:07:53,000
It's supposed to work.

152
00:07:54,000 --> 00:07:56,000
And just need long platform in front of the character.

153
00:07:56,000 --> 00:08:01,000
So now I'll do a double jump and do it again and I go off the platform in a full state.

154
00:08:01,000 --> 00:08:02,000
Perfect.

155
00:08:03,000 --> 00:08:03,000
Perfect.

156
00:08:03,000 --> 00:08:05,000
Perfect, perfect.

157
00:08:05,000 --> 00:08:07,000
Now there is something else we could do.

158
00:08:07,000 --> 00:08:08,000
Let me see.

159
00:08:08,000 --> 00:08:09,000
How long is the video?

160
00:08:11,000 --> 00:08:12,000
It's okay.

161
00:08:12,000 --> 00:08:15,000
Something else we could do to help us in the future.

162
00:08:16,000 --> 00:08:20,000
It is to put this movement in function.

163
00:08:20,000 --> 00:08:21,000
Let's do this.

164
00:08:22,000 --> 00:08:27,000
And let's select the line click alt enter to call submenu and extract method.

165
00:08:27,000 --> 00:08:29,000
And I'm going to call it.

166
00:08:29,000 --> 00:08:30,000
Movement.

167
00:08:30,000 --> 00:08:31,000
All right.

168
00:08:32,000 --> 00:08:39,000
Now, at this point, we have a movement function and if we want to change movement behavior, somehow

169
00:08:39,000 --> 00:08:42,000
we can do it in this function and we want the clutter update too much.

170
00:08:43,000 --> 00:08:48,000
There is some more changes I want to do to this, but let's keep it for the next videos.

171
00:08:48,000 --> 00:08:53,000
Don't want to clutter your head with a bunch of information.

172
00:08:53,000 --> 00:08:54,000
Let's take it step by step.

173
00:08:54,000 --> 00:08:55,000
So let's go to the next video.

