 All right, so let's start this off by creating that base rigid body script. All right, and like I said, I like to do this just because it separates kind of the responsibilities of the classes, you know, this base rigid body script is going to be Responsible for setting up and just getting the rigid body up and running I like doing things like weight conversion and just checking to see if it's even there first off and Then the you know the drone controller is going to handle Controlling the actual drone and doing all the you know banking and rolling and pitching and yawing and all that stuff. So Let's jump into unity and get started. All right, so let's go over into the code folder and into our scripts folder And let's make a new script and I'm gonna call this IP Or actually we're gonna call this base Rigid body. I Got ahead of myself there for a second. I also want to change a little icon On my scripts just so to note that you know, they're my scripts instead of just the default C-sharp scripts So if you go and look into that zip folder that I included with this particular course this mini course There's this any pixel icon now you can use that if you want I just asked that you don't use it in your regular work that you might sell or You know, I would highly recommend just making your own icon. It's really simple It's just a 32 pixel by 32 pixel image But let's drag and drop this into the editor here editor folder. All right And let me show you guys how to set up that little icon So it's really easy you just select the script that you want to change and then you go to hit the little icon on it over Here and the inspector and then select the other button and then just go look for the particular texture So I just typed in indie up here and that comes up with the indie pixel icon And then you just kind of click off of it and it'll go and update the icon for you So just nice little, you know, customized thing to do for your scripts makes it feel like a pro at least Again, yeah, I highly recommend making your own, but I just wanted to show that too. They also show up inside of the Editor the scene editor and they they actually become selectable too So really cool stuff and that actually reminds me. I should turn this guy back up here like so there we go All right, cool. So let's do our base rigid body So I'm going to double click that to open it up into visual studio 2019 And let's take care of our namespace just like we usually do so say any pixel like so And remember this particular script is really just responsible for dealing with the rigid body All right, and just getting things set up just so we don't have you know a bunch of Rigid body based controllers in our projects and they all have their own functionality to set up a rigid body We can just extend or inherit from this one particular script for all of our vehicles All right, so I'm going to do a require component and it's going to be a type of rigid body So again, this will just make sure that the rigid body is actually assigned to our game object Okay, so with that done, let's go and create a region. So I'm going to do variables Like so and there's actually a way to set this up. So you don't have to type this in if you have a common Setup that you always use for your particular scripts like like I do I always basically do this over and over again You can actually there's a template file and I just can't remember off off the top of my head What where it is it is in the unity engine folder There's some temp file that you just need to update and I'll fix all this stuff up So I'm sure you could Google it and it'll there's be like a million different Resources about it. So all right. So the first thing I want to do is I want to allow users To assign a weight to this. Okay. So first thing I'm gonna do I'm actually gonna put a header here And I'm gonna call this rigid Body properties. All right, so this is just a nice way to keep things organized in the Inspector, okay, and then I'm gonna do a public on actually, let's just do this. Let's do a private float Weight in pounds and I'm gonna set that to one. Let's say, you know, these drones are pretty light And it really depends on the type of drone. Obviously the larger they get the heavier they get All right, so I'm just gonna initialize it to one pound But we made a private so this means it's not, you know, accessible by other scripts But it also means that it doesn't show up in the inspector But we want to be able to change this in the inspector, but I don't want other classes to change this value So we make a private and then we do the serialized field Attribute, all right, and that basically makes it so it shows up in the the inspector All right, so the we also need another private variable and this is going to be the rigid body So we're gonna say rigid body. I usually call that RB for short All right, and what we need to do is right when the game starts We need to assign this rigid body variable with the actual rigid body that's being attached by this required component Okay, so to do that I'm actually going to change this void start to awake So it gets called before all the start functions get called. Okay, so I'm ensuring that you know We're gonna look for the rigid body first All right, so we're gonna say RB is equal to get component and we're gonna be looking for a rigid body That type, okay cool Awesome, so now we got that all set up. We're gonna get the rigid body So we could do some setup here what with this weight in pounds All right, and that basically means I want to allow users to set the how much this weighs in pounds Okay, and I'm just sticking the pounds because it's what I'm used to What I'm gonna do is I'm actually going to create a constant value. Okay, so I'm gonna do a const All right, and I am going to say I'm gonna call this particular variable It's gonna be a float. It's gonna be called pounds to kilograms or kg Okay, so if you're used to kilograms and by all means that the reason why I'm doing this is because unity by default works in kilograms So not pounds, but because I'm used to working in pounds, right? Because you know just the region I live in basically and how I was raised I Do this conversion. So you don't have to do this. That's my point. So the conversion is To we want to multiply whatever pounds we have here that's been assigned by the user by this Constant ratio value basically so 0.454 Okay, so let's do that. Let's take care of that now. We're gonna go in here. I'm gonna say if RB if we have a rigid body basically, okay, then let's set the mass so we're gonna say RB dot mass is equal to our weight in pounds times our pounds to kilograms conversion All right, and you can look up if you have other conversions you want to do you can look them up on Google Just type in, you know, whatever unit of measure you want to start in and the unit of measure you want to convert to and Google will tell you what The conversion factor is Okay Cool. So the next thing I want to do is I want to if we're going to be inheriting from this particular script I want some sort of Overrideable function in here that handles the actual physics processing. Okay, so and we'll talk about overrides once we get to the drone controller So what we want to do is we want to say if Inside of our update function and actually we need to set this to a fixed update because we're working in physics All right, so I'm gonna say if not RV So if we didn't find an original body for some reason it got detached somehow or destroyed Who knows but you should always check for this So if we don't have it, we should return and not execute any code below this particular statement here Okay, so I'm gonna say if not rigid body Okay, so if this is null basically we're gonna return and so the fixed update will just constantly be returning And no any code below here won't be run and the code that I want to run down here is Function that I'm gonna call handle physics And I'm gonna make this overriderable Okay, so you're gonna get a red squiggly line there because we haven't actually implemented the handle physics So let's do that now. So we're gonna make another region. This is gonna be custom methods like so Don't say and regent like so and then we'll say We're gonna say protected right because I want to be able to I want to protect this class But I also want to have all Classes that inherit from this base rigid body class to be able to to see this function So I make a protected not private and I don't I'm not making it public because I don't want any other script to see this Okay, so I say protected virtual void. It's not gonna return anything. It's virtual because we want to override it All right, meaning the implementation in the other scripts are gonna have its own set of code Okay, we're gonna say handle physics like so And then our squiggly marks or curly braces Awesome, and we don't need to put anything in it because the script is not gonna do anything with it I just want to set it there and then in the drone controller will go and add the actual meat or the code that goes in there All right, so that is pretty much everything. I think the next thing I want to do let's Let's actually create two more protected variables here. I really only need the weight and pounds to be Exposed so I'm gonna do a protected start drag All right, so this is a good idea to do And we actually need to give it a type. So there's gonna be a float value. There we go This is a good idea to do because When you want to start to do Dynamic drag, which you should write for some sort of physics-based Object or a vehicle You want to update the drag as something is going faster, right? Obviously the faster we're going the more drag we're creating Right because we're you know having to force ourselves through the air basically in the case of a drone So you want to increase the drag. You don't want it just a constant drag and that won't feel as realistic, right? cool, so with these two variables Let's go and Assign it so I'm gonna say start drag is equal to whatever, you know, the drag has been Set to in the inspector. All right, so that is if I go back in the unity over here and select the drone Oh, we don't have a rich body So I'll point that out once we finish up the script here But it's basically whatever value Is is set in the inspector there. So we'll say RB dot angular drag All right, we just want to initialize those values and make it protected so any you know Class that's inheriting from the script has access to the data and these variables All right, so with that we're pretty much good to go. So let's go back in the unity now and Let's assign it to the drone and see all the awesomeness happen. So let's Let's click and drag this over onto our drone and you can see it created a rigid body And we have the weight and pounds and our header look at that Nice and organized now. We're not actually going to be putting this base rigid body script I really just want to put that on there Just to show you guys how it works. We're gonna in the next lecture We're going to create the drone controller which inherits from this base rigid body class So it will also create the rigid body for us as well Okay, so with that let's close out the lecture and move on to the next