 Howdy guys. All right, so what I wanted to do in this lecture is to show you a quick little trick that I did to make sure that the drone Basically doesn't lose any altitude as you're basically rolling left and right or pitching forward or anything like that And now while this isn't necessarily realistic a lot of these drones that you can buy these tiny little drones that are meant You know for beginners they take care of all that they basically make it so that it's almost You know impossible to lose control of the drone Whereas like in a real drone like a racing drone or something like that You do have to manage your altitude with you know throttle adjustments, right? But in this case, you know, it's a game type of controller And so you really want the player to be focusing on the fun aspect of the game rather than Trying to manage the altitude or the through the through throttle adjustments now that being said if you're making a simulation Yeah, go for you. You probably want people to manage their own throttle adjustments. So With that said, let's move on and take a look at what I came up with. All right. So before we begin I want to try to demonstrate, you know, what i'm Going to be doing here and somehow I renamed that to e All right, so let's actually pull this up a little bit here Now, you know when you are You know flying flat our current velocity or the the amount of force that we are producing if we go back to our engine Is you know this Rigid body or the mass times gravity, right? And that's enough force, right to counteract gravity Well, when we actually rotate this Right, all the engines Up vectors are now tilted right whereas before when it's flat all the up vectors are the The force vector that we are generating is straight up. So it's able to counteract gravity Whereas when we're down here, what happens? Let me see if I can get my little drawing Tool Well, let's just open up. Let's do a snippet here really quick. So let's take a look here So let me actually just get just the scene view here And we'll focus on this right here. All right, so Basically what I'm talking about is Let me actually erase that guy. So Well, let's go and get the pen. So by default, you know, we are creating an up vector That's like that, right when we're flat But since we're pivoted, you know, or rolled over in this current shot here Our, you know, new vectors over here, right? Well, the y value the y component of this vector Actually only reaches to right here, right? That means we're not producing enough upward force anymore And that's why our rigid body is falling out of the sky And so what we need to do is we actually need to find that difference. We need to find the difference right here How much more force do we need to, you know, produce? And add on to this vector when we're tilted over. Okay, so hopefully that clears things up for you guys That's basically what we are looking to achieve. All right, so let's actually Reset this guy on to the ground again. Very cool Okay, so let's go into Little studio here. We'll go to the engine script All right, so the first thing I want to do is I'm going to create a new vector is free. All right I'm going to call this my We'll call this no, let's let's call it up back Something like that. All right, and it's currently going to be initialized to the transform dot up like so, okay And then what I want to do is I want to say up back Dot x is equal to zero. I really just want to get just the y vector and this Seem to work for me. I'm sure if you guys have any other suggestions. I'm totally open to it All right, so I'm just zeroing out the actually we want to do the z there So I'm zeroing out all the other components. So all we're left with is the y value Okay, and so what we need to do now is we need to Subtract so we need to say float diff Is equal to one minus the up back Dot magnitude. All right, so that basically gives us the leftovers, right? The the percentage that we need to Basically multiply from physics dot gravity dot magnitude. All right, so let's do this. We'll call this the float Final diff and that stands for difference, right? I could probably come up with a better Variable name for that but for now that's fine. So I'm just going to do physics dot gravity dot magnitude times our diff Right and that basically will return for us the extra amount that we need to apply To this force here. So we'll do this with you plus final diff like so all right That basically adds that on now now. We shouldn't drop out of the sky Right, so it's just kind of a little fix just to make it easier to fly this thing Again, like I said, you can totally Leave it the way it is that's totally valid too I just like this because then then I can focus on gameplay, you know elements rather than trying to manage the the drone itself All right, let's let's take a look here now. So I'm going to go lift up and as I Move to the left and right you can see That's I'm actually going up a little bit too much there And so we're not getting the exact value So let's go back to the code here really quick and I think I actually just need to put this inside here instead Honestly, you don't really even need to do all that but it just kind of keeps it clean All right, let's go check that out now Let's hit play And go up a little bit Yeah, there we go So much better a lot easier to fly So now you can you know really maintain Your altitude here if I can actually see well, that's why we need a camera though Um, this is kind of fun actually Just flying this around like this I mean it feels like you know what you would actually have in real life Yeah, nice I dig it totally cool Awesome. All right. So that's that. Let's move on to the next lecture