 Well, welcome back. Okay, so now that we have our base rigidbody class in place Let's go and create the drone controller now, and we'll start to see how all this stuff is, you know, hooked together All right, so let's get going. Alrighty. Let's go and get the drone controller So what I would need to do is I need to remove the Rigidbody in the base rigidbody. So just to show you, you know, how that require a component, you know, works and protects our our Controllers, let's try to remove the Rigidbody. So I'm going to go and say remove component What it's going to do it's going to tell me you can't remove the component because this base rigidbody Has said that it requires that Rigidbody. All right So that just really helps you make sure that all the components that you need are attached to your game object. Okay So the way to get rid of all this is we need to delete the base rigidbody first So we're going to go and say remove component And then we can remove the Rigidbody because there's no dependencies now. Okay, so let's remove that All right, so let's go over into the scripts folder here and go and say create new C sharp script And we're going to call this IP drone controller Yeah All right, there we go And I'm going to go and change the icon in the sky. So let's get the indie pixel icon And click off of it to assign it There we go. So now we're all official. Let's go and Double-click it before we assign it to our drone model or game object and let's take care of some code first So we're going to say namespace is indie pixel All right again just to protect the code Keep it all compartmentalized And what we want to do in here for our required components. We want to make sure that we in fact do have a Drone input script. So I'm going to say require Components and we're gonna say type of All right, so we're using type of there. Here we go So type of and we're gonna say IP drone Inputs I just want to make sure that that particular script is in place. Remember the drone inputs Also, make sure that we have a player input. So we're kind of creating this cascading, you know set of dependencies All right, so that really just helps you Set up a new drone really quickly Even if you know, you have someone who's setting up the drones who hasn't done all the code They they won't miss any of the components or anything like that All right, so Now we come down to the class and what we're doing was we're currently inheriting from money behavior is that base class in unity, right? That gives us access to You know all the functions that we use over and over like start and update, right? Well, the base rigid body inherits from money behavior So and we want to include all of this code that we just wrote All right, I want to write this inside the drone controller. All right, that would be redundant So let's go and just inherit from our base rigid body So now we get all of money behavior and we get all of our custom code, right? And then we also have access to this virtual function right here that we can override So pretty cool way to go about setting all this stuff up. They call it object-oriented oriented programming Okay, so that's kind of your first step into that. So we're just inheriting from another class So we get all that functionality All right, so let's go and create a new region and these can be my variables again You can always set up your templates if you want And in this case, we are just going to type them again because it doesn't take that long honestly All right, we don't need update because remember now that we're inheriting from the base rigid body class We already have a fixed date update running. What we want to do is just write our own implementation of handle physics Okay, so I'm going to come into drone controller and we'll do our region we'll say custom methods down here and Region and what we'll do is we're going to say protected override And then if you hit space the IntelliSense will tell you that well because we're you know inheriting from base for your body You have one option here and that's that handle physics. So you can just double-click that And there we go. So now we're overriding it and we're calling the base base dot handle physics It means it's going to call whatever code we might have written in the base implementation in this case There's nothing so we don't need to actually call the base. There are times when you would have to do that though All right, so what do we want to do here? So in our handle physics We want to go and call a couple things. So we're gonna, you know be controlling some Engines and we're also going to be controlling the actual Controls for this like pitch and roll and and yaw. So we need two functions here. We're gonna say handle Engines like so and we're gonna do handle controls And then we need to actually write this implementation. So we're gonna do Void and actually let's make these protected virtual as well We might want to make other types of drones. All right, so to do that We're gonna do a virtual this allows us again to override whatever we write In here inside of this particular function in another implementation of a drone controller Okay, so hopefully that makes sense. We'll call this handle engines There we go, and then we'll do another protected virtual Void handle controls like so Awesome All righty now remember also just to reiterate, you know, how cool inheritance is This handle physics won't run if there is no rigid body So if we go the you know base implementation here in the base rigid body class Nothing will run if a rigid body is not detected. All right, so This is it's really nicely, you know, organized so that we reduce the amount of errors we can we will create Cool. All right. So the next thing we need some variables up here So what I'm gonna do is I'm going to create a new header up here. We'll call this some engine properties like so and What I want to do is I want to create a list of engines, but we actually don't have that class yet So I am going to change this to Drone properties. How about our control properties? Let's see even better. All right, so let's start here. We're gonna say private Float and we want to do the min max pitch All right. We're gonna initialize that the 30 and then we want another one. We'll say private Float min max roll. All right, so this is the the rolling and we'll initialize that the 30 as well And then we want to do a private float yaw power Now these are just names that I had come up with earlier You're more than welcome to you know name them whatever you want You know, you'll get more of an idea of what you want to name them once we get through more of the Physics and stuff. These are just names I came up with All right, so we're also going to need another private variable and this needs to be the inputs, right? So the IP drone inputs and I'm just going to call this input for the variable name All right, so what we should do because we're requiring the component We know we're going to have one there So let's populate this variable with the actual component. All right, so we're going to say input is equal to get component all right and We want to look for the IP drone inputs Like so Cool. All right, so that basically will grab the instance The drone inputs now will give us access to the properties that we made Earlier on. All right, so then we could get the values using these properties Okay, cool. So next thing we need to do I think that's actually pretty much it. Oh You know what we need to do. We need to make sure these show up in the editor or in the inspector So we need to do a serialized field on all these guys. Oops Let's copy those and paste those guys down like so very cool and Let's do something with Let's just prove Physics in general. How about that? So let's prove that, you know, we're actually inheriting from This particular class All right, and that our weight is actually working and assigning it properly to the mass So how do we actually make something? How do we actually make an object to sit or hover in the air? Basically counteracting the force of gravity. Well, the equation for that would be mass times gravity, right? so if we take the current mass of our particular object and we multiply it by the the magnitude of gravity, right? In which case Instead of unity if we go to our project settings and we go to physics it's set up for earth gravity All right, so it's negative 9.81. Okay, but if we take the magnitude of that, it's going to be a positive number So it'll be 9.81. All right So if we do mass times gravity or the magnitude of gravity and multiply an up force So vector 3 dot up and we apply that as a force to our particular model or our object The object won't go anywhere because we're literally Counteracting the force of gravity with the exact same amount of force. All right, so let's take a look at this. All right So I'm going to do RV and it looks like where's my base rigid body over here Aha, so let's make the rigid body protected not private. There we go. I didn't have access to it because It was private right even though we are inheriting from the base rigid body because this variable is private It's localized to just the base rigid body class now that I made it protected any class that inherits from base rigid body We'll now have access to it. So now I can say RB. Yep, there we go. So it's add force All right, so we're gonna add a force. So in this case, let's just do vector 3 Dot up. All right, and we want to multiply that by Our RV dot mass so the mass times the gravity or the magnitude of the gravity, right? So we say physics Dot gravity dot Magnitude Like that. All right, so if everything's hooked up, right? And I just kind of positioned the drone anywhere in space It's not on the ground the drone won't go anywhere All right, because we are applying an equal and opposite force to the force of gravity All right, so we're counteracting gravity and this is how we make things hover right and this is just a basic example here But there's a great way to just prove that all that stuff is working. So Let's go back into unity over here and go back to the inspector over here And let's drag and drop our drone controller on to our drone game object and look at that. We have a rigid body We have our drag an angular drag. So the start drag and the start angular drag are gonna get their values from here Okay, and our weight and pounds is one so one pound and now let's go and Lift this up in the air a little bit and get a better shots here. They're angle on this I think that's cool. And then let's just hit play and look at that Even though on the ridge about it. We saw gravity turned on right? We're not going anywhere because we're creating a force that is counteracting the force of gravity Cool All right, and we are on our way. So I'm gonna close the lecture there and move on to the next