What you will learn
In this Unity tutorial, we will learn how to effectively utilize the game engine. Over the tutorial, we will learn how to use the Unity editor interface as well as how to navigate in the scene view. From there, we will learn how to import assets and how to create prefabs. Then we will shape our level even more by adding character controllers, colliders, lights, materials and physics. We will then finish the tutorial by learning how to use scripting in order to make our level interactive.
In this lesson, we're going to learn how to use physics inside of the Unity game engine. OK, so what I want to do with the physics portion of this lesson is I want to actually create just a rigid body on top of this cryochamber that is going to make it fall over whenever the level starts. So the first thing that I want to do is actually go ahead and create a collider for this specific cryopod that is actually attached to it. So if I select this object, you'll notice that I don't actually have a component on here that says that it has a collider, OK? So at this point, what I want to do is go ahead and actually grab one of these capsules here-- the one that is actually on it-- and what I'm going to do is actually parent it to my cryopod. So I want to make sure that I have the right one selected. So this is the second cryopod closed. So let's take our capsule, and let's drag this right on top of our cryopod closed. Make sure it's the second one here. And it's going to ask me. It's going to tell me I'm going to lose my pre-fab, and I'm just OK with that. So I hit Continue. And now, what I have is a capsule collider right on top of this object here. So if I go to cryopod closed, I now have a collider attached to it, OK. All right, so let's go ahead and apply a rigid body collider to this, or rigid body physics to this. So we're going to go to Component, Physics, and then Rigid Body. OK, so now a rigid body component has been applied to this object. And now, what we can do is actually mess around with some of these options that we have available to us. So I'm going to briefly discuss what each one of these do. So we have mass here, and this is the weight of our object. So by default, we're going to keep it at one. And it's just going to have some weight. I don't want it to bounce around like a bubble or anything like that. I just want it to actually just have weight. Now, I could take this up much higher if I wanted to. So I could take this up to 50, and it would become heavier. It would act heavier. Now, I don't actually have another physical object that it's going to interact with. So we're not really going to see the mass compared to that. So we have drag. And you can see here that the drag is actually going to be kind of like fraction, OK? We have angular drag. And we have use gravity. So I want this to actually use gravity in my scene. So I'm going to make sure that that is checked. And is kinematic, and basically what this means is if we have this checked, it's not going to be dynamic. It's not just going to fall. It waits for us to actually animate this object. It's able to interact with other physics objects, but it doesn't actually dynamically animate itself. So it waits for us to use a transformation tool to animate it. Now, we have interpolation and collision detection, OK? Now, we have different types here on our interpolate and collision detection. And without getting into this too much, this is really going to help us with whatever object is going really fast, it's going to have some problems colliding with other objects, OK? Once it hits a certain velocity, it's just going to ignore physical objects and go right through it. OK, so what we can do is actually set this up to be continuous. And that would help us out with that. And we can do continuous dynamics, and it would help us out even more with that, OK? So we're not really going to get too heavy into this. So let's go ahead and test this out. So let's go ahead and hit play. And we'll see that our cryopod has fallen over, and it's actually fallen through our wall there. So what we have here is a problem. We've actually got our wall that has no collisions on it. So what we need to do is go ahead and put on a mesh collider on this one. So this is one that we forgot in one of our early lessons. So let's go to Physics and Mesh Collider. We'll add that component there, and we should be OK now. So let's go ahead and play this. And we'll see that our cryopod falls back, and then it rolls over, OK? Now, you'll notice that it's rolling-- it's not really following the contours of our object. And what it's doing is it's actually using that capsule to use physics. It's not actually using the cryopod itself. So if you want it to be a little more realistic and bounce around, then you would probably want to go ahead and use an actual Mesh Collider. But I think this is pretty good just the way it is. I like the way it rolled over. I liked the way it moved. So I was pretty happy with that. So we're just going to go ahead and stick with that. So now, whenever we hit play, it goes back to its normal position. Now, what we could do if we want to is we could put a physics object on this one and make it rigid body. And they could roll together. And possibly, this first one could hit this and knock it over and start a domino effect or something like that. So you could really play around with this. So I know that that's a very brief understanding of how rigid body works inside of Unity. But this should get you started on how to start working with those physics inside of the Unity game engine. So what we're going to do in our next level is we're actually going to finish this level. We're going to get it to a state to where it's actually nice, and pretty, and everything is textured, and we've got plenty of props in, and we're probably going to take a couple of lessons to do this. So I'm going to show you how we can put the materials back on our cryopods, and how we can add some more props, and imports some more packages, and really make this nice and neat to where we're ready to finish this off, OK? So we'll do that in our next lesson.