In this lecture, we'll learn about collision detection and collision resolution and we'll learn how colliders and physics materials in Unity help us with that. So let's start with collision detection. Not surprisingly, collision detection is detecting collisions between two game objects in our scene. And it's really easy for us to get collision detection to work, all we have to do is attach 2D colliders to our game objects and then the 2D physics engine in Unity, will detect collisions between those game objects. The next thing we do is collision resolution. So this is resolving the collision we've detected doing something in response to that collision. So as long as we add materials to our colliders, we can have the physics engine determine how that collision gets resolved how the objects bounce off of each other or not for example based on friction and bounciness for the colliders. We can also implement our own collision resolution in case we want to do something else, reduce health as a result of the collisions and so on. So let's go to Unity and see how we can make all that happen. Before we start adding colliders and physics 2D materials, I want to show you a change that I made to our mover script. So this is the new code that actually gets our game object moving and the idea is that the game object will move with a random speed and a random direction. So these first two lines of code, give a range of impulse forces to apply, the next line of code generates a random angle between zero and 2 pi. So that's between zero and 360 degrees or between 0 and 2 pi radians. And then I generate a direction vector using cosine of that angle and sine of that angle. So some beginning programmers are sort of intimidated by the math that we need to do, and luckily, using Unity's physics engine we don't have to do a whole lot of calculus but we do need to do some trigonometry. And so sines and cosines are part of the stuff we need to do as programmers. Okay, the next thing I do is I generate a magnitude of the force by getting a random number between min impulse force and max impulse force. And then finally, I get the rigid body 2D component and I add the force that I've just come up with. Direction is a vector and magnitude is a float. So when I multiply a vector times a float, I'm multiplying magnitude times this for X and magnitude times this for Y. So that gives me that random impulse force vector using my random direction and my random magnitude and it's an impulse force. So that is distinct from all the collider stuff we're going to work on today but it actually gets our game object moving in a random direction with a random speed. To see that happen, I'll run the game and you can see the teddy bear goes down like that. I'll run it again and it goes in a different direction with a slightly different speed, it might be hard for you to see the difference in speed. So there you go. Okay, let's actually start adding some colliders. Because, if I let those run long enough, the teddy bear will get going and then he just leaves the game window and that's not what we want to have happen. What we need to do is, for the teddy bear, we need to add a collider. And over here in the inspector I'll add a component and I'll add a physics 2D box collider. And then I will double click the teddy bear in the hierarchy window. And as you can see there's a collider around the teddy bear now although it's not really tight up against the teddy bear. Back in the inspector, I can click this box next to edit collider and I'll click that so now I can come back into the scene view and I can grab the edges of the collider to make them more tightly match the edges of the teddy bear. And then when I'm done editing, I click edit collider again. Okay, when I run the game now, the teddy bear still leaves because it doesn't collide with anything. So I'll double click the main camera and zoom in a little using control and the scroll wheel on my mouse. So really what we need to do is, we need to provide something for the teddy bear to collide with. So I'm going to add an edge collider on one edge of the main camera. So I'll add a component, physics 2D and this time it will be an edge collider and I can now edit that edge collider and I will drag the ends of it to the edges of the window. And I'll click this again. Now another way you can edit edge colliders is if you expand this point area. I happen to know that for this size camera, the Xs are actually 5.333 and the Ys are actually 3. So if you don't want to drag stuff around, you can actually just edit the values directly as the point. Okay, this will let the teddy bear collide with the left edge of the game window but not the other three edges. So I'm going to just go add those other three colliders and then we'll come back. And as you can see, I now have four edge colliders on my main camera. And by the way, the way you can minimize information about a particular component, is you just click that little arrow next to it so you can maximize and minimize that information as necessary. When I started producing this lecture, I discovered that it was going to be longer than I wanted it to be. So I've broken it into two parts and this is the end of part one.