In this lecture, we'll learn about collision detection and resolution. And we'll learn how collisions and physical materials help us with that in unreal. So, what's collision detection? You won't be surprised to hear it's detecting a collision between two Actors in a map. If both of those Actors have a collision, a collidable volume for that Actor, then the PhysX engine can detect those collisions automatically. And I know that terminology is a little difficult because the collidable volume is called a collision, and the collision between two Actors is called the Collision. But we'll just deal with that unreal terminology. A collision is a collidable volume for an Actor. What's collision resolution? It's doing something as a result of the collision. So physical materials help the PhysX engine determined how the collision should be resolved from a physical perspective. And we'll learn later in the specialization that we can also do our own custom, the collision resolution from within scripts. Let's go see how all that works. If we navigate to our static mesh for the yellow teddy bear and double click it to open up the mesh editor. We can actually look at the collision that was added when we imported the model. I'm coming up here to the toolbar on the top and expanding this and showing simple collision. And then I'm zooming in and you can see That we have a collision volume or what in unreal engine is just called a collision already associated with this mesh. If you don't like that particular collision, you can come up to collision on the top menu bar, and you can remove the collision that was added when we imported the mesh. But I'm not going to do that. But if you want to, you can remove that, and then you can add a different collision to this particular mesh. And you can add a sphere, which looks like a sphere. You can add a capsule, which looks like a capsule, and you can add a box. So sphere, capsule and box are pretty efficient collisions. You can add other types of collisions as well, but I'm just going to use the default collision that we got when we imported the mesh. I need to add a floor for the teddy bears to bounce off. So, I'm going to get rid of this from when I added the camera to the scene, and I'm going to drag a cube over into the game. I'm going to need to manipulate the cube to make it like a floor. And so, I'll center it in 0 and why? And I'll put it at -149, which through trial and error, I have determined is a good place when we display it with the orthographic camera. I also need to scale it and why? To make it extend the full width of the scene. And I'll also make it thinner because I don't need that much there. You'll see I have a message that said, Lighting needs to be rebuilt, so I'll do that. And now when I run the game, the teddy bears fall down and laying on the floor. Now, I'd like the teddy bears to bounce more than that. So, I'm going to add something called the physics material to each of the blueprints that I'm using for these teddy bears. These are the blueprints that we had from the previous lecture when we did some basic physics. So, I'm going to go to content and go into my Collisions folder, and I'm going to add another folder called Physics. I'll go into the Physics folder. I'll right click and I'll say Physics, Physical material. I'll select Physical material as the class I want to use and click the green button, and I'm going to rename this Physics material, pm underscore teddy bear. If I double click it, I can edit the Physics material and the two things that were going to care about are friction and restitution. So friction is just as you'd expect, sort of how sticky it is when you try to slide along it. We're just going to leave friction just as it is. But restitution is bounciness. And I would prefer a rubber teddy bear compared to a 0.3 bouncy teddy bear I guess. So, the scale of all these values are 0 to 1. So, I'll make the teddy bear as bouncy as possible by setting this to 1. And I'll save it and close this. While I'm here, I know from past experience that I want the floor to be a little bouncy also, so I'll create another physical material For the floor. And I'm going to call this one PM floor. And I'm going to leave the friction the same. I'm going to make it kind of bouncy but not totally bouncy, because I know that I get too much bounciness. But this is the kind of thing that you sort of play around with and figure out what works best for your game. Okay, I'll save this. And now, I need to attach the physical materials to each of the Actors that I want them attached to. For the floor, which I have selected here. And in fact, why don't I just come up here and change its name from cube to floor? That's a little more descriptive. And I can scroll down, in the floor And under collision, I can override. This is hard to read because it's cut off a little. It's Physics material override and I'm going to peg PM floor as the physical material to use for the floor. For the teddy bears, it'll be easiest for me to modify each of the blueprints rather than modifying these Actors that are already in the map. So, I'll go to Content, my Blueprints folder, and I'll double click each one, select the static mesh, scroll down over here and under Collision, I'll select Teddy bear. I'll compile because I changed the blueprint and I'll save. And I'll do that for the other two as well. So select mesh, scroll down to Collision and pick Teddy bear, Compile, Save. And now when we run the game, we've made our teddy bears really bouncy, as bouncy as possible. And we've made our floor pretty bouncy, not the maximum, and we can see what happens. And that's pretty good. You've just watch that and be hypnotized, but I'm going to stop it. The other thing that we want to have happen is we want teddy bears to actually bounce off each other as well. And I'm going to show that that's happening by adding another teddy bear to the scene pretty much right below the yellow teddy bear that's right there. I'll slide it over a little. And over here on the right, I need to make sure it's at 0, and then I'll slide it over. And now these two teddy bears will bounce off of each other, as you can see, and they bounce on top of each other and they fall over and all kinds of great stuff. That was a nice little flip. Now, something that you haven't seen is this game running with 18 teddy bears, six of each color. So I'm going to go add them, and then we'll come back, so you can see that. Okay, so I've made it. So, I have six teddy bears of each color. When I run the game now, you'll see they bounce off each other and we've lost some of them out of the game, which is sad for me. So, let's make one more change. I'm going to add walls on the two sides so I can drag in another cube. I can change its name to Write wall. And I can place and scale it properly. So, I've placed it on the right hand side and I'll make it skinny and I'll make it tall enough. And again, I messed around with those different settings to place the wall in the right place. And one more cube over here At 0. -261, 0. And again scaling it as 0.1 2.88. And I haven't added any physical material to these, but I do need to rebuild the lighting. So the teddy bears that bounce off the wall will bounce off them a little bit. Not a lot like the bounciness from the floor. So, one more time we'll play the game. And the teddy bears bounce around for a while and then stop, but we still have all 18. To recap, in this lecture, you learned how collisions, those collidable volumes help the PhysX engine perform collision detection. We saw how physical materials help the PhysX engine determine how to resolve those collisions from a Physics perspective. And I also told you, though I didn't show you that later in the specialization, we can also do custom collision resolution from within our scripts.