﻿1
00:00:04,300 --> 00:00:05,350
‫Hello and welcome.

2
00:00:05,350 --> 00:00:10,840
‫This lecture we're going to be sorting out the colliders on our barrels so that we can stack them up

3
00:00:10,840 --> 00:00:15,880
‫properly, as you can see here, and have fun just plowing into them and knocking them down.

4
00:00:15,880 --> 00:00:18,100
‫Let's dive in and see how this is done.

5
00:00:19,140 --> 00:00:19,530
‫Okay.

6
00:00:19,530 --> 00:00:23,750
‫So I would like to be able to stack items on top of this rack.

7
00:00:23,760 --> 00:00:30,240
‫Now, we can do this fairly straightforwardly by just getting a barrel and dragging it on to the rack.

8
00:00:30,240 --> 00:00:35,910
‫And you can see Unreal automatically tries to position it on top and we can do that effectively.

9
00:00:35,910 --> 00:00:41,490
‫Then we can hit simulate physics and we can hit play and see that it jumps around a little bit, but

10
00:00:41,490 --> 00:00:42,720
‫not massively.

11
00:00:42,720 --> 00:00:43,800
‫So that's quite cool.

12
00:00:43,800 --> 00:00:50,130
‫And we can now shoot at the rack and have everything fall down in the process.

13
00:00:50,130 --> 00:00:50,520
‫It's funny.

14
00:00:50,520 --> 00:00:55,470
‫It's kind of got its legs stuck in the ground though, which is a little bit annoying.

15
00:00:55,620 --> 00:00:58,200
‫We will work on tweaking some of these bugs.

16
00:00:58,200 --> 00:01:02,220
‫It may well be that the mesh is a little bit too far on the ground.

17
00:01:02,220 --> 00:01:08,640
‫If we select the mesh and the barrel and bring it up slightly, then it shouldn't be penetrating the

18
00:01:08,640 --> 00:01:12,150
‫ground and hopefully won't get stuck in the way that it just did.

19
00:01:12,150 --> 00:01:16,590
‫And we've got a little bit of a fun set up that we can knock stuff over.

20
00:01:16,590 --> 00:01:25,800
‫However, you will notice if you tried or did try earlier to stack these barrels on top of each other,

21
00:01:25,800 --> 00:01:31,830
‫they can get pretty unstable pretty quickly, even if we give them a little bit of separation so that

22
00:01:31,830 --> 00:01:38,040
‫we know they aren't clipping into each other and popping because of that reason, we give them a little

23
00:01:38,040 --> 00:01:42,540
‫bit of separation, but let's select them both because they haven't got physics enabled.

24
00:01:42,540 --> 00:01:44,340
‫Let's select them both and add physics.

25
00:01:44,340 --> 00:01:51,870
‫If I duplicate this and bring up another level and make sure my tower is nice and straight, and if

26
00:01:51,870 --> 00:01:58,800
‫we hit play now, we see that it pops up in the air like this and is incredibly unstable.

27
00:01:58,800 --> 00:02:00,510
‫So why is it doing this?

28
00:02:00,510 --> 00:02:02,400
‫Why is it being so unstable now?

29
00:02:02,400 --> 00:02:08,970
‫The reason for this is because of collisions and the way collisions are calculated in Unreal.

30
00:02:09,000 --> 00:02:13,560
‫There is a mesh here which is essentially let me show you what a mesh is.

31
00:02:13,560 --> 00:02:18,570
‫Actually, if we go to the viewport and hit the button that currently says Lit and select wireframe

32
00:02:18,570 --> 00:02:21,150
‫instead, this is what the mesh is.

33
00:02:21,150 --> 00:02:26,880
‫This is essentially what the computer is seeing and rendering for us with the application of materials.

34
00:02:26,880 --> 00:02:30,630
‫So you can see there's this complicated looking mesh for the barrel.

35
00:02:30,630 --> 00:02:33,180
‫But this isn't what is used for physics.

36
00:02:33,180 --> 00:02:34,530
‫No, for physics.

37
00:02:34,530 --> 00:02:39,480
‫There is a simplified version of this mesh to make physical calculations a lot easier.

38
00:02:39,480 --> 00:02:46,290
‫So if you click where it now says wireframe instead we can change the view mode down to player collision.

39
00:02:46,290 --> 00:02:48,870
‫And this shows us the simplified collision mesh.

40
00:02:48,870 --> 00:02:56,130
‫And you can see it's a little bit wonky, it's a little bit jagged and not ideal for having clean collisions.

41
00:02:56,130 --> 00:02:57,600
‫So we can change this.

42
00:02:57,600 --> 00:03:04,680
‫We can modify the collision mesh fairly easily and unreal by going to the content draw and selecting

43
00:03:04,680 --> 00:03:12,690
‫our barrel mesh and double clicking it, which brings up the static mesh editor and we can see what

44
00:03:12,690 --> 00:03:13,620
‫the mesh is like.

45
00:03:13,620 --> 00:03:14,910
‫We can kind of click on it.

46
00:03:14,910 --> 00:03:21,990
‫We can look at the wireframe view again by clicking on lit and switching to wireframe or switching to

47
00:03:21,990 --> 00:03:23,130
‫player collisions.

48
00:03:23,130 --> 00:03:30,690
‫And what we can do is there is a collision button in the toolbar and we can click on that and click

49
00:03:30,690 --> 00:03:36,870
‫remove collisions, which is going to remove any collisions that are currently there, such as slightly

50
00:03:36,870 --> 00:03:38,100
‫janky collisions.

51
00:03:38,190 --> 00:03:43,680
‫If we go back to the main level, you can see there's now no mesh visible in our player collisions.

52
00:03:43,680 --> 00:03:47,700
‫And if we hit play you can see they just pass straight through the floor because there's nothing for

53
00:03:47,700 --> 00:03:48,810
‫them to collide with.

54
00:03:48,810 --> 00:03:55,980
‫So what we need to do is go back to our mesh editor and select the collision dropdown again.

55
00:03:55,980 --> 00:04:02,490
‫And we can do we can add in a simplified collision that is going to be much better suited for this.

56
00:04:02,640 --> 00:04:10,020
‫And what we want to do is add the ten dop z axis simplified collision.

57
00:04:10,020 --> 00:04:11,790
‫Now, let me just explain this.

58
00:04:11,790 --> 00:04:13,850
‫In fact, the tooltip kind of explains this.

59
00:04:13,860 --> 00:04:21,930
‫It says it generates a new axis aligned box collision mesh with four Z axis aligned edges, beveled

60
00:04:21,930 --> 00:04:23,850
‫and ten total sides.

61
00:04:23,850 --> 00:04:28,890
‫That's pretty confusing, but if I add it in, it might make it a little bit clearer.

62
00:04:28,890 --> 00:04:29,700
‫I've add it in.

63
00:04:29,700 --> 00:04:35,070
‫You can see this is what the mesh actually looks like and you can see what it's sort of meant by Z axis

64
00:04:35,070 --> 00:04:35,760
‫aligned.

65
00:04:35,970 --> 00:04:42,780
‫It's most of its complexity is around the Z axis trying to wrap around this barrel and it's flat on

66
00:04:42,780 --> 00:04:48,930
‫the tops and the bottoms, which is exactly what you want really when you're trying to model a barrel.

67
00:04:48,930 --> 00:04:51,810
‫So I'm pretty happy that that's a good collision mesh.

68
00:04:51,810 --> 00:04:58,440
‫We can now save the mesh, go back to our level and you can see that the player collision view is showing

69
00:04:58,440 --> 00:05:03,720
‫us the new collision mesh, which is a lot simpler and less deformed.

70
00:05:03,720 --> 00:05:10,560
‫So I can now switch the view mode back from player collision to lit and we can see all the lighting

71
00:05:10,560 --> 00:05:17,010
‫and materials and we can go ahead and hit play now and you can see that these barrels are a lot more

72
00:05:17,010 --> 00:05:18,600
‫stable than they were previously of.

73
00:05:18,700 --> 00:05:22,150
‫See when I go ahead and hit them, they aren't any more.

74
00:05:22,150 --> 00:05:28,510
‫So I'm going to challenge you to create a blueprint barrel class here so that we don't have to go and

75
00:05:28,510 --> 00:05:31,930
‫change settings on every single barrel all the time.

76
00:05:31,930 --> 00:05:34,990
‫So go and click that convert to blueprint button.

77
00:05:34,990 --> 00:05:40,660
‫Just a reminder, it's the one in the details pane that looks like a little tiny blueprint graph.

78
00:05:40,660 --> 00:05:44,740
‫Then you're going to keep the defaults and just change the name.

79
00:05:44,740 --> 00:05:48,550
‫And remember that we use the BP underscore naming convention.

80
00:05:48,880 --> 00:05:50,710
‫I'd like you to increase the barrel mass.

81
00:05:50,710 --> 00:05:57,340
‫At the moment they are very flimsy and fly around very easily when hit and build a wall out of these

82
00:05:57,340 --> 00:06:01,540
‫barrel out this barrel class and have fun knocking it over.

83
00:06:01,540 --> 00:06:03,190
‫Pause the video and have a go.

84
00:06:06,310 --> 00:06:06,940
‫Okay.

85
00:06:06,940 --> 00:06:07,650
‫Welcome back.

86
00:06:07,660 --> 00:06:10,740
‫So let's create a barrel class, shall we?

87
00:06:10,750 --> 00:06:18,100
‫So I'm going to take one of these barrels and I'm going to hit the convert to blueprint.

88
00:06:18,100 --> 00:06:25,930
‫Then I'm going to change the name to BP, underscore barrel, and I'm going to change the path as well

89
00:06:25,930 --> 00:06:29,680
‫so that it's in the root of the content folder and hit select.

90
00:06:29,680 --> 00:06:33,460
‫Then it's going to automatically open up our newly created class.

91
00:06:33,460 --> 00:06:38,950
‫I'm going to dock this to the main window and I'm going to go and select the static mesh components.

92
00:06:38,950 --> 00:06:42,530
‫Scroll on down to the physics section, make sure physics is enabled.

93
00:06:42,550 --> 00:06:43,270
‫It is.

94
00:06:43,270 --> 00:06:50,620
‫I'm going to increase the mass to about I think 1000 in my testing has been quite fun in the past and

95
00:06:50,620 --> 00:06:55,690
‫I'm going to save the blueprint and now I'm going to delete the barrels that I currently have in my

96
00:06:55,690 --> 00:06:59,320
‫scene because I want to use my new barrel class instead.

97
00:06:59,320 --> 00:07:07,030
‫Then we're going to go ahead and open up the content drawer and drag in a barrel instance into our scene.

98
00:07:07,030 --> 00:07:10,810
‫And I want to stack these up in to a wall.

99
00:07:10,990 --> 00:07:13,600
‫Before I do that, I'm going to stick them inside a folder.

100
00:07:13,600 --> 00:07:19,540
‫So I'm going to right click in the outline on the newly created barrel, and I'm going to select the

101
00:07:19,540 --> 00:07:26,320
‫move to option create new folder, and I'm going to call this barrel wall with no spaces just because

102
00:07:26,320 --> 00:07:27,520
‫that's my preference there.

103
00:07:27,520 --> 00:07:34,960
‫And then selecting that barrel, I'm going to click on the Z axis to drag the barrel up and then repeat

104
00:07:34,960 --> 00:07:38,590
‫and probably one more time to make it nice at all.

105
00:07:38,590 --> 00:07:44,470
‫Then selecting all four of those I can duplicate out to the side a couple of times, then selecting

106
00:07:44,470 --> 00:07:48,040
‫all the barrels in the outline and moving myself to the side.

107
00:07:48,040 --> 00:07:55,990
‫I can alt click on the red arrow to bring a couple of rows backwards of my barrels like so, and we

108
00:07:55,990 --> 00:07:59,440
‫probably want some stacked here on top of the rack as well.

109
00:07:59,440 --> 00:08:06,970
‫So let's go back to a content drawer and drag in from there a couple of barrels for our rack and some

110
00:08:06,970 --> 00:08:08,560
‫for the top as well.

111
00:08:08,560 --> 00:08:12,580
‫And while we're at it, let's stack a few of these on top of each other.

112
00:08:12,620 --> 00:08:15,760
‫Should make them more fun to knock down when we do.

113
00:08:15,760 --> 00:08:18,220
‫So, let's play and see what this looks like.

114
00:08:18,220 --> 00:08:22,630
‫So I've got my barrel wall dominating here in front and I've got the rack.

115
00:08:22,660 --> 00:08:24,160
‫Let's try shooting at the rack.

116
00:08:24,160 --> 00:08:29,350
‫Well, that's very satisfying to knock those over and then we can shoot at this barrel wall as well

117
00:08:29,350 --> 00:08:32,260
‫and create a lovely bit of carnage.

118
00:08:32,380 --> 00:08:37,540
‫Now, you may notice that occasionally the ball goes flying through the walls or the barrels, and this

119
00:08:37,540 --> 00:08:42,340
‫is because it's moving so fast that the physics simulation doesn't really keep up.

120
00:08:42,340 --> 00:08:44,560
‫Now we won't be fixing it in this section.

121
00:08:44,560 --> 00:08:47,860
‫It's a little bit beyond the scope of what we're trying to do.

122
00:08:47,890 --> 00:08:54,160
‫So one thing you can do to ameliorate this if you want to, is to reduce the speed of the balls and

123
00:08:54,160 --> 00:08:55,840
‫it will happen less often.

124
00:08:56,020 --> 00:08:57,130
‫Great stuff.

125
00:08:57,130 --> 00:09:02,620
‫So hopefully you've enjoyed putting some barrel physics in here and getting the colliders working and

126
00:09:02,620 --> 00:09:04,030
‫I'll see you in the next lecture.

