‫Hello and welcome.
‫This lecture we're going to be sorting out the colliders on our barrels so that we can stack them up
‫properly, as you can see here, and have fun just plowing into them and knocking them down.
‫Let's dive in and see how this is done.
‫Okay.
‫So I would like to be able to stack items on top of this rack.
‫Now, we can do this fairly straightforwardly by just getting a barrel and dragging it on to the rack.
‫And you can see Unreal automatically tries to position it on top and we can do that effectively.
‫Then we can hit simulate physics and we can hit play and see that it jumps around a little bit, but
‫not massively.
‫So that's quite cool.
‫And we can now shoot at the rack and have everything fall down in the process.
‫It's funny.
‫It's kind of got its legs stuck in the ground though, which is a little bit annoying.
‫We will work on tweaking some of these bugs.
‫It may well be that the mesh is a little bit too far on the ground.
‫If we select the mesh and the barrel and bring it up slightly, then it shouldn't be penetrating the
‫ground and hopefully won't get stuck in the way that it just did.
‫And we've got a little bit of a fun set up that we can knock stuff over.
‫However, you will notice if you tried or did try earlier to stack these barrels on top of each other,
‫they can get pretty unstable pretty quickly, even if we give them a little bit of separation so that
‫we know they aren't clipping into each other and popping because of that reason, we give them a little
‫bit of separation, but let's select them both because they haven't got physics enabled.
‫Let's select them both and add physics.
‫If I duplicate this and bring up another level and make sure my tower is nice and straight, and if
‫we hit play now, we see that it pops up in the air like this and is incredibly unstable.
‫So why is it doing this?
‫Why is it being so unstable now?
‫The reason for this is because of collisions and the way collisions are calculated in Unreal.
‫There is a mesh here which is essentially let me show you what a mesh is.
‫Actually, if we go to the viewport and hit the button that currently says Lit and select wireframe
‫instead, this is what the mesh is.
‫This is essentially what the computer is seeing and rendering for us with the application of materials.
‫So you can see there's this complicated looking mesh for the barrel.
‫But this isn't what is used for physics.
‫No, for physics.
‫There is a simplified version of this mesh to make physical calculations a lot easier.
‫So if you click where it now says wireframe instead we can change the view mode down to player collision.
‫And this shows us the simplified collision mesh.
‫And you can see it's a little bit wonky, it's a little bit jagged and not ideal for having clean collisions.
‫So we can change this.
‫We can modify the collision mesh fairly easily and unreal by going to the content draw and selecting
‫our barrel mesh and double clicking it, which brings up the static mesh editor and we can see what
‫the mesh is like.
‫We can kind of click on it.
‫We can look at the wireframe view again by clicking on lit and switching to wireframe or switching to
‫player collisions.
‫And what we can do is there is a collision button in the toolbar and we can click on that and click
‫remove collisions, which is going to remove any collisions that are currently there, such as slightly
‫janky collisions.
‫If we go back to the main level, you can see there's now no mesh visible in our player collisions.
‫And if we hit play you can see they just pass straight through the floor because there's nothing for
‫them to collide with.
‫So what we need to do is go back to our mesh editor and select the collision dropdown again.
‫And we can do we can add in a simplified collision that is going to be much better suited for this.
‫And what we want to do is add the ten dop z axis simplified collision.
‫Now, let me just explain this.
‫In fact, the tooltip kind of explains this.
‫It says it generates a new axis aligned box collision mesh with four Z axis aligned edges, beveled
‫and ten total sides.
‫That's pretty confusing, but if I add it in, it might make it a little bit clearer.
‫I've add it in.
‫You can see this is what the mesh actually looks like and you can see what it's sort of meant by Z axis
‫aligned.
‫It's most of its complexity is around the Z axis trying to wrap around this barrel and it's flat on
‫the tops and the bottoms, which is exactly what you want really when you're trying to model a barrel.
‫So I'm pretty happy that that's a good collision mesh.
‫We can now save the mesh, go back to our level and you can see that the player collision view is showing
‫us the new collision mesh, which is a lot simpler and less deformed.
‫So I can now switch the view mode back from player collision to lit and we can see all the lighting
‫and materials and we can go ahead and hit play now and you can see that these barrels are a lot more
‫stable than they were previously of.
‫See when I go ahead and hit them, they aren't any more.
‫So I'm going to challenge you to create a blueprint barrel class here so that we don't have to go and
‫change settings on every single barrel all the time.
‫So go and click that convert to blueprint button.
‫Just a reminder, it's the one in the details pane that looks like a little tiny blueprint graph.
‫Then you're going to keep the defaults and just change the name.
‫And remember that we use the BP underscore naming convention.
‫I'd like you to increase the barrel mass.
‫At the moment they are very flimsy and fly around very easily when hit and build a wall out of these
‫barrel out this barrel class and have fun knocking it over.
‫Pause the video and have a go.
‫Okay.
‫Welcome back.
‫So let's create a barrel class, shall we?
‫So I'm going to take one of these barrels and I'm going to hit the convert to blueprint.
‫Then I'm going to change the name to BP, underscore barrel, and I'm going to change the path as well
‫so that it's in the root of the content folder and hit select.
‫Then it's going to automatically open up our newly created class.
‫I'm going to dock this to the main window and I'm going to go and select the static mesh components.
‫Scroll on down to the physics section, make sure physics is enabled.
‫It is.
‫I'm going to increase the mass to about I think 1000 in my testing has been quite fun in the past and
‫I'm going to save the blueprint and now I'm going to delete the barrels that I currently have in my
‫scene because I want to use my new barrel class instead.
‫Then we're going to go ahead and open up the content drawer and drag in a barrel instance into our scene.
‫And I want to stack these up in to a wall.
‫Before I do that, I'm going to stick them inside a folder.
‫So I'm going to right click in the outline on the newly created barrel, and I'm going to select the
‫move to option create new folder, and I'm going to call this barrel wall with no spaces just because
‫that's my preference there.
‫And then selecting that barrel, I'm going to click on the Z axis to drag the barrel up and then repeat
‫and probably one more time to make it nice at all.
‫Then selecting all four of those I can duplicate out to the side a couple of times, then selecting
‫all the barrels in the outline and moving myself to the side.
‫I can alt click on the red arrow to bring a couple of rows backwards of my barrels like so, and we
‫probably want some stacked here on top of the rack as well.
‫So let's go back to a content drawer and drag in from there a couple of barrels for our rack and some
‫for the top as well.
‫And while we're at it, let's stack a few of these on top of each other.
‫Should make them more fun to knock down when we do.
‫So, let's play and see what this looks like.
‫So I've got my barrel wall dominating here in front and I've got the rack.
‫Let's try shooting at the rack.
‫Well, that's very satisfying to knock those over and then we can shoot at this barrel wall as well
‫and create a lovely bit of carnage.
‫Now, you may notice that occasionally the ball goes flying through the walls or the barrels, and this
‫is because it's moving so fast that the physics simulation doesn't really keep up.
‫Now we won't be fixing it in this section.
‫It's a little bit beyond the scope of what we're trying to do.
‫So one thing you can do to ameliorate this if you want to, is to reduce the speed of the balls and
‫it will happen less often.
‫Great stuff.
‫So hopefully you've enjoyed putting some barrel physics in here and getting the colliders working and
‫I'll see you in the next lecture.