1
00:00:03,120 --> 00:00:07,500
In this lecture, I'm going to show you my amazing pixel art skills, because I've provided you with

2
00:00:07,500 --> 00:00:12,240
a mushroom that we're going to add some physics material to DX two so that we can bounce to get out

3
00:00:12,240 --> 00:00:13,410
of sticky situations.

4
00:00:13,410 --> 00:00:17,010
We're also going to fix the issue where the player was sticking to the walls.

5
00:00:17,010 --> 00:00:21,410
We're going to make it so you can't stick to the walls anymore and you slide up and down them smoothly.

6
00:00:21,420 --> 00:00:23,970
Let's start first by adding our bouncy mushroom.

7
00:00:23,970 --> 00:00:26,880
So I've gone and created a crazy little mushroom for you.

8
00:00:26,880 --> 00:00:28,770
I'm going to put it in my sprites folder.

9
00:00:28,770 --> 00:00:30,810
You can download it against this lecture.

10
00:00:30,810 --> 00:00:36,330
Side note I created this in libraries right after following along with our pixel art course.

11
00:00:36,330 --> 00:00:41,970
So if you have any interest whatsoever in making a way better mushroom than the mushroom I made, you

12
00:00:41,970 --> 00:00:47,070
can go through the pixel art course and get some pretty cool pixel art skills really fast allows you

13
00:00:47,070 --> 00:00:51,090
to make little things like what I've made, and I'm going to bring that in my mushroom.

14
00:00:51,720 --> 00:00:52,260
Here it is.

15
00:00:52,260 --> 00:00:53,910
In here you can see a little mushroom.

16
00:00:53,910 --> 00:00:56,340
If I click, I get the preview over yonder.

17
00:00:56,340 --> 00:00:59,340
Okay, just a little red mushroom, nothing too fancy.

18
00:00:59,340 --> 00:01:01,080
But I wanted to have something we could bounce on.

19
00:01:01,110 --> 00:01:03,870
I also need a spot in my level here where we can bounce.

20
00:01:03,870 --> 00:01:05,459
I'm going to put this over here, I think.

21
00:01:05,459 --> 00:01:11,790
Just rearrange my level very briefly, jump onto the eraser, make sure I'm on the correct tile map

22
00:01:11,790 --> 00:01:12,780
platforms, tile map.

23
00:01:12,780 --> 00:01:17,160
Just do a little bit of deletion in here so we've got something to bounce on and then go boing from

24
00:01:17,160 --> 00:01:18,000
A to B.

25
00:01:18,000 --> 00:01:19,290
I think that'd be pretty nifty.

26
00:01:19,320 --> 00:01:22,470
Get rid of a couple of these things as well, because when I was prototyping this, I kept bouncing

27
00:01:22,470 --> 00:01:27,960
up into the roof, which is kind of fun, but be good to have none of that roof bouncing going on.

28
00:01:27,960 --> 00:01:32,730
And I'm also going to click my player hit and move my player over to the left, more of the start of

29
00:01:32,730 --> 00:01:35,700
the level type thing down in this little spot just there.

30
00:01:35,720 --> 00:01:36,900
We'll be putting my mushroom here.

31
00:01:36,900 --> 00:01:42,090
So what we need to do is create a new tile map, which is going to be all about bouncing on things.

32
00:01:42,090 --> 00:01:49,830
So click on tile map grid, right click find to the object and then tile map and then rectangular.

33
00:01:49,860 --> 00:01:54,600
I'll name this bouncing tile map and we'll go and add the fundamental things we need.

34
00:01:54,600 --> 00:01:56,070
So we need our tile map.

35
00:01:56,070 --> 00:01:58,530
Collider To DX Add component.

36
00:01:58,530 --> 00:02:02,460
We need our composite collider to DX to have a rigid body.

37
00:02:02,460 --> 00:02:03,990
Yes, we have a rigid body in there already.

38
00:02:03,990 --> 00:02:04,800
So we need the tile map.

39
00:02:04,800 --> 00:02:07,290
Collider We need the rigid body and we need composite.

40
00:02:07,290 --> 00:02:10,979
Collider 2D and one of these things in here, we need to mark as static.

41
00:02:10,979 --> 00:02:16,620
So rigid body, 2D static so that our tile map doesn't go flying down into the nether regions.

42
00:02:16,620 --> 00:02:17,940
Nether Is that the right word?

43
00:02:17,940 --> 00:02:21,240
Netherworld Nether regions I don't think that's quite correct actually.

44
00:02:21,240 --> 00:02:23,640
I think netherworld might be more accurate.

45
00:02:23,640 --> 00:02:25,560
Sorry if I've said the wrong thing there.

46
00:02:25,560 --> 00:02:27,900
Now next up, we need a process, our mushroom.

47
00:02:27,900 --> 00:02:30,720
So I'm going to click on the mushroom, drag it over into the tile map.

48
00:02:30,720 --> 00:02:33,090
That should ask me to save something somewhere.

49
00:02:33,090 --> 00:02:33,720
It has.

50
00:02:33,720 --> 00:02:35,130
We're going to put this in.

51
00:02:35,130 --> 00:02:35,880
Let's see.

52
00:02:35,880 --> 00:02:38,850
Assets and then tiles.

53
00:02:38,850 --> 00:02:40,410
And that will be the mushroom.

54
00:02:40,410 --> 00:02:41,100
Excellent.

55
00:02:41,100 --> 00:02:42,660
And you can see it's kind of tiny on there.

56
00:02:42,660 --> 00:02:45,630
That's because we haven't changed the pixels per unit.

57
00:02:45,630 --> 00:02:49,200
So I'm going to click on the mushroom, look over on the right hand side, pixels per unit should be

58
00:02:49,200 --> 00:02:52,110
32 because I created it as a 32 by 32.

59
00:02:52,140 --> 00:02:54,570
We're going to apply what we're here will jump into the Sprite editor.

60
00:02:54,570 --> 00:02:57,480
Just play around with the collision of this.

61
00:02:57,480 --> 00:03:03,030
I'm going to actually create a custom physics shape that will looks like it does nothing, but you have

62
00:03:03,030 --> 00:03:04,350
to click to start the process.

63
00:03:04,350 --> 00:03:06,570
So I'll click in the bottom corner here or drag.

64
00:03:06,570 --> 00:03:11,700
I think I need to do yet drag and then I'm going to drag the points just to where I need them.

65
00:03:11,700 --> 00:03:14,820
If you need another point, I won't put this exactly lined up.

66
00:03:14,820 --> 00:03:16,800
I'll put a bit over to the left side, a little bit forgiving.

67
00:03:16,800 --> 00:03:19,140
If the player kind of lands around about there, it'd be fine.

68
00:03:19,140 --> 00:03:22,680
It'll do some bouncing click anywhere on the line that will create a new point.

69
00:03:22,680 --> 00:03:25,740
Pop that all the way over to there another point.

70
00:03:27,070 --> 00:03:29,050
Clicking points, clicking points.

71
00:03:29,500 --> 00:03:29,900
There we go.

72
00:03:29,920 --> 00:03:31,360
Now we've got our customer's physical shape.

73
00:03:31,390 --> 00:03:34,050
Click on Apply X out of that.

74
00:03:34,060 --> 00:03:36,510
This shape should now have some good physics on it.

75
00:03:36,520 --> 00:03:43,300
If I'm selected on the bouncing tile map, super important click on the mushroom and then go into the

76
00:03:43,300 --> 00:03:45,280
world and click to drop that in there.

77
00:03:45,280 --> 00:03:49,240
You can see that it doesn't appear, although you can see the little outline of the collision doesn't

78
00:03:49,240 --> 00:03:51,850
appear because of sorting order.

79
00:03:51,850 --> 00:03:55,080
So let's find our tile map renderer sorting order.

80
00:03:55,090 --> 00:03:58,930
Let's see, this will be the same sorting as the platforms, I think.

81
00:03:58,930 --> 00:04:03,040
I don't see that the mushroom would ever be in front or behind of the platform.

82
00:04:03,430 --> 00:04:04,840
It is its own entity.

83
00:04:04,840 --> 00:04:08,620
So we'll say it's at the same visual level as platforms.

84
00:04:08,620 --> 00:04:09,550
Now we can see it.

85
00:04:09,550 --> 00:04:10,930
We also need to handle collision.

86
00:04:10,930 --> 00:04:12,400
So let's go up into layer.

87
00:04:12,430 --> 00:04:13,690
I'm going to add a new layer too.

88
00:04:13,710 --> 00:04:14,830
So we don't have any conflicts.

89
00:04:14,830 --> 00:04:18,010
We'll call this bouncing jump back onto the bouncing tarmac.

90
00:04:18,010 --> 00:04:20,320
So we're doing this all at the tile map level.

91
00:04:20,320 --> 00:04:25,980
So everything that we apply to the tile map will have these particular rules, including the bouncing.

92
00:04:25,990 --> 00:04:27,040
This will do in a moment.

93
00:04:27,040 --> 00:04:30,820
So I'll change the layer here to bouncing and that should be all pretty cool.

94
00:04:30,820 --> 00:04:34,750
Let's just check that that's working, that the player can run and at least collide with the mushroom

95
00:04:34,750 --> 00:04:35,440
over there.

96
00:04:35,440 --> 00:04:36,940
Jump, jump, jump, jump.

97
00:04:36,940 --> 00:04:37,150
Yep.

98
00:04:37,150 --> 00:04:38,980
I can collide and I can land on it.

99
00:04:38,980 --> 00:04:42,850
Can't jump off the mushroom because we haven't created that logic in our code.

100
00:04:42,850 --> 00:04:43,510
That's fine.

101
00:04:43,510 --> 00:04:45,100
I think this will only be for bouncing.

102
00:04:45,100 --> 00:04:49,180
I don't see a time where we need to actually jump on it because as soon as we touch it, it's going

103
00:04:49,180 --> 00:04:52,240
to go boing and push us way off into the distance.

104
00:04:52,240 --> 00:04:55,240
Now the next step I'm going to, let's say, my assets folder.

105
00:04:55,240 --> 00:04:56,470
Where shall we put this?

106
00:04:56,620 --> 00:04:59,680
I'm going to create a new folder, right click create folder.

107
00:04:59,680 --> 00:05:08,110
We'll call this materials double clicking materials, right click create a 2D Physics material, 2D.

108
00:05:08,110 --> 00:05:15,520
And I will name this bouncy bounce just to be very professional with my naming.

109
00:05:15,520 --> 00:05:19,690
Now you can see if you haven't played around with physics materials before, we've got these two values

110
00:05:19,690 --> 00:05:20,870
friction and bouncing.

111
00:05:20,870 --> 00:05:23,110
This friction we'll get to later.

112
00:05:23,110 --> 00:05:26,530
Bouncing us is going to show how much we bounce off there.

113
00:05:26,530 --> 00:05:28,120
If it's zero, there'll be no bounce.

114
00:05:28,120 --> 00:05:29,680
That's zero on there at the moment.

115
00:05:29,680 --> 00:05:32,200
So I'm going to put this to say 1.5.

116
00:05:32,200 --> 00:05:33,670
So we have a value at one.

117
00:05:33,670 --> 00:05:37,630
It means that if we drop from a certain height, we should bounce back up to that same height.

118
00:05:37,630 --> 00:05:42,130
But if it's 1.5, if we drop from that height, we should bounce up 50% higher.

119
00:05:42,130 --> 00:05:47,080
I think that's going to work out the maths on that might not be exact, but I know that a value over

120
00:05:47,080 --> 00:05:51,580
one is going to have us go jumping higher and a value under one is going to have us go lower.

121
00:05:51,580 --> 00:05:53,680
So I'll put that at 1.5.

122
00:05:53,680 --> 00:05:55,930
Click back on the bouncing tile map.

123
00:05:55,930 --> 00:05:57,370
Now we need to find the right spot.

124
00:05:57,370 --> 00:06:01,300
There's a couple of spots in here that ask for material so you can see on the tile map.

125
00:06:01,300 --> 00:06:06,130
Collider Also on Rigid Body, it asks for a material also on the composite.

126
00:06:06,130 --> 00:06:08,890
Collider I'm going to put this one on the tile map.

127
00:06:08,890 --> 00:06:10,060
Collider 2D.

128
00:06:10,120 --> 00:06:13,450
So if that works, cross our fingers, hope for the best.

129
00:06:14,050 --> 00:06:15,070
Click on play.

130
00:06:17,070 --> 00:06:18,870
That's often how game development is, isn't it?

131
00:06:18,870 --> 00:06:20,040
Just try things, see if it works.

132
00:06:20,040 --> 00:06:21,420
Jump and boing.

133
00:06:21,420 --> 00:06:22,290
That's a nice bounce.

134
00:06:22,290 --> 00:06:22,680
Excellent.

135
00:06:22,680 --> 00:06:27,780
So the cool thing about this is if I didn't jump on the mushroom, I can't actually escape here.

136
00:06:27,870 --> 00:06:32,070
I can at the moment because we've got this dodgy wall climb thing, a double jump thing.

137
00:06:32,070 --> 00:06:35,880
But I need to actually use the mushroom to bounce out of the hole in there.

138
00:06:35,880 --> 00:06:39,270
So we've got ourselves another game mechanic, which is really neat.

139
00:06:39,270 --> 00:06:42,930
I mean, you fly a little bit too far and if you stay on it, you go a little bit crazy.

140
00:06:42,930 --> 00:06:45,390
But that could be fun in your game if you want to do that.

141
00:06:45,390 --> 00:06:48,180
And the trick there is to play around with the value.

142
00:06:48,180 --> 00:06:52,140
So if you don't want it to be quite so bounce that bounce and get more and more, then you can put it

143
00:06:52,140 --> 00:06:53,370
closer to one.

144
00:06:53,370 --> 00:06:55,110
But for now that's fine with me.

145
00:06:55,110 --> 00:06:59,040
You can jump on the mushroom to escape that pit that we're in.

146
00:06:59,040 --> 00:06:59,370
Excellent.

147
00:06:59,370 --> 00:07:01,440
So that's the first part of using physics material.

148
00:07:01,470 --> 00:07:04,620
2D, I've got these mushrooms, you can have different sorts of things.

149
00:07:04,620 --> 00:07:09,780
Remember, with this particular approach, this approach that I've shown you here, all anything we

150
00:07:09,780 --> 00:07:12,930
put on this time map will have the same 1.5 bouncing ness.

151
00:07:12,930 --> 00:07:17,340
So with this particular strategy, you couldn't have big mushrooms that make you fly a long way, little

152
00:07:17,340 --> 00:07:19,530
mushrooms that make you fly a smaller way.

153
00:07:19,530 --> 00:07:23,490
You'd need to have separate tile maps to do that if you're going to do that particular approach.

154
00:07:23,490 --> 00:07:27,570
Of course, if you wanted to have something that was a different bouncing profile, you could go and

155
00:07:27,570 --> 00:07:32,760
create a game object and put that into the world and have that have a different bounce profile.

156
00:07:32,760 --> 00:07:34,350
So you could have a bunch of different game objects.

157
00:07:34,350 --> 00:07:39,120
But we're trying to do this all within tile maps at all lines up nicely and works with the tile map

158
00:07:39,120 --> 00:07:39,590
structure.

159
00:07:39,600 --> 00:07:44,190
Next up, what we're going to do is stop the behaviour where the player is gripping to the wall.

160
00:07:44,190 --> 00:07:46,260
This is also a physics material issue.

161
00:07:46,260 --> 00:07:49,590
So at the moment I can go jump, jump, jump, jump, jump, jump, jump, jump, jump.

162
00:07:49,590 --> 00:07:51,270
And I'm grabbing onto the wall.

163
00:07:51,270 --> 00:07:51,900
I don't want that.

164
00:07:51,900 --> 00:07:54,060
You might want to have wall jumps in your game and that's cool.

165
00:07:54,060 --> 00:07:54,900
You can play around with that.

166
00:07:54,900 --> 00:07:55,830
But for me, I want to have it.

167
00:07:55,830 --> 00:07:58,980
So I don't actually I don't actually stick to the wall.

168
00:07:58,980 --> 00:08:00,120
I don't get stuck like this.

169
00:08:00,120 --> 00:08:02,700
This is the main thing I'm trying to stop being able to do.

170
00:08:02,700 --> 00:08:05,100
So this is a challenge for you to play with friction.

171
00:08:05,100 --> 00:08:09,780
Stop the player from gripping to the walls by applying a new physics material 2D to the player.

172
00:08:09,780 --> 00:08:10,470
So pause the video.

173
00:08:10,470 --> 00:08:11,070
Take that on.

174
00:08:11,070 --> 00:08:12,240
See you back here when you're done.

175
00:08:15,570 --> 00:08:15,950
Okay.

176
00:08:15,960 --> 00:08:18,470
This one should be reasonably quick, I think.

177
00:08:18,480 --> 00:08:26,940
Well, in our materials folder, right click create two dx physics material two dx I'll call this friction

178
00:08:27,570 --> 00:08:29,130
should probably be called no friction.

179
00:08:29,130 --> 00:08:29,940
No friction.

180
00:08:29,940 --> 00:08:31,470
That would be a smarter name, wouldn't it?

181
00:08:31,470 --> 00:08:32,640
Rick Yes, it would.

182
00:08:32,640 --> 00:08:34,110
Rick okay.

183
00:08:34,110 --> 00:08:36,450
Talking to yourself, first sign of insanity, friction.

184
00:08:36,450 --> 00:08:38,250
I'm going to put to zero bouncing us.

185
00:08:38,250 --> 00:08:41,370
I'll leave at zero as well, then click on the player.

186
00:08:41,370 --> 00:08:42,690
Where do we want to put this?

187
00:08:42,690 --> 00:08:43,679
Probably on the capsule.

188
00:08:43,679 --> 00:08:45,990
Collider I think we've got our material here.

189
00:08:45,990 --> 00:08:50,040
I'll click on the selector, no friction, click on play.

190
00:08:50,040 --> 00:08:53,880
And if we don't do the stuck to the wall running thing, mission accomplished.

191
00:08:53,880 --> 00:08:54,450
Yep.

192
00:08:54,840 --> 00:08:55,320
Awesome.

193
00:08:55,320 --> 00:08:57,540
So I'm pushing left, but I'm not sticking.

194
00:08:57,540 --> 00:08:59,280
I can still do the extra wall jump.

195
00:08:59,280 --> 00:09:02,130
That's something we're going to fix in the next video, but for now, we've got it.

196
00:09:02,130 --> 00:09:06,090
So the player is sliding down the walls instead of accidentally gripping, getting stuck.

197
00:09:06,090 --> 00:09:10,680
And we've also made ourselves a fun, little bouncy mushroom kind of thing to add an extra gameplay

198
00:09:10,680 --> 00:09:11,820
mechanic into our game.

199
00:09:11,820 --> 00:09:12,360
There we go.

200
00:09:12,360 --> 00:09:13,410
I'll see you in the next lecture.

