 Welcome back. Okay, so what we're going to do in this lecture is we're going to get it so we can actually move the drone around All right, so this is things like pitch and roll and yaw All right, so let's go back into our drone controller over here and we're gonna go and take care of handling the controls now So we have all of our main Properties or our variables set up. I think we have everything we need so far at least So let's take care of all these. So let's do the pitch first so we're going to say that float pitch is equal to our input and We're going to get the cyclic Dot y and we're going to multiply that by our min max Pitch because remember the cyclic dot y returns negative one or one So if we multiply that by our max pitch, we're going to get a value between negative in this case currently negative 30 and 30 All right, and let's spell that correctly Not flay out There we go. All right, then we need to do float roll All right, so let's say input dot cyclic Go Dot x. All right, and we'll do the same thing. We'll say times min max roll Pretty easy stuff and then we'll do the float yaw Yaw and we'll do input dot pedals And Yep, we multiply that by our yaw power go and it's capital P. I believe. Yeah, there we go All right, so now we've got these values going what we can do is we can build what is called a quaternion If you're not familiar with quaternions. It's a way to handle rotations. Okay inside of unity and They actually have a bunch of built-in functions that makes this process real easy So let me let me walk you through the process. So I'm going to create a new quaternion. All right Well, and we're going to store it in a variable called rot for rotation and then we're going to utilize the quaternion dot Euler Function this allows us if I just put in the parentheses parentheses there This allows us to actually just pump in a bunch of float values. So x y and z All right, so for the x if you remember if we go back to unity over here, and I select my drone Right here if we want to rotate this on the x direction. That's good. That's going to be our Our pitch value that's forward and back right a roll is going to be z and our yaw is going to be y All right, so with that information in mind Let's do that. So we need our pitch For x our roll our yaw is going to be our y and then our roll is going to be our z like so and then all we need to do is assign that to our Transform or the rigid body so rigid body dots move rotation now I'm going to use move rotation. You are more than welcome to Add torque if you want to you'll just have to go and Clamp it so that you don't just make the whole Rigid body flip right so we're going to move rotation and you can see that it's expecting a quaternion So I'm just going to give it a rot like so All right, so this is just a this is a more I would say arcadey way of doing it Adding torque would be the more realistic way of course for sure But this gets the job done as well. Okay, so let's go and take a look at this really quick let's go back into unity and Let's go and test all this stuff out now All right, so let's make some space again I'm going to go back here hit Q on the keyboard to get rid of the transform I'm going to pick up my Xbox controller hit play and Let's lift off a little bit and let's test it out. Look at that And I could tell obviously right off the bat our rotation is really wonky It's just popping into place. I don't like that at all, but it is working The X direction is actually reversed so we could do we could do a lot of things in this case What I'm going to do is just reverse The cyclic X by putting a minus sign right there All right, so let's get rid of the popping to us since we're here inside of the script and to do that We are going to make some private variables. So I'm going to say private floats a final Pitch and we're going to do another private float Final roll. All right, and we're going to do another private float final yaw there we go and Then what we need to do, let's just do some lurps. All right, so we're going to say Final pitch is equal to math F Lurp like so We're going to learn from final pitch to the wanted pitch So the one to pitch is the one that we're building right here, right? And then we need to learn by some value and I'm going to use time Dot delta time time some, you know lurt value. So let's actually expose that up here, too So let's do a private float Lurp speed. We'll just use this for everything. So it's a 2f to initialize it And then let's copy our serialized field attribute here And make it all official so you can see it in the inspector And so we just want to put our Lurp speed in here now All right, so we need to do the same thing for roll. So let's do final roll is equal to math f dot lurt And we'll do final roll to roll by time delta time times lurt speed And then finally we're going to do our yaw. So final yaw is equal to math F Dot lurt and you could also use a smooth damp, too. There's another one. It works a little different, but It works just fine. It'll give you nice smooth values I usually start with lurt's when I'm doing this stuff and then, you know, wherever I see an opportunity to Use the smooth damp where I want to actually control how long something actually takes to get to its final destination That's where I use a smooth damp All right, whereas the Lurt just kind of gets there based off of unit time dot delta time times Lurt speed in this case So we'll say Lurt speed and there we go So now rather than doing these guys, let's just do final pitch All right, final roll for the z-axis and then final yaw for the y There we go. That'll be much smoother now All right, we'll let that compile and let's play Let's take off. Yeah. So there we go. So now we're working. Yeah, look at that. We have a drone It's actually pretty fun to fly and honestly this all started because I got a little new little drone That has a camera on it and I've been flying around my house and I was just like, oh, man It'd be so sweet to actually make that and inside of you maybe To practice This would make actually you could hook this up with like some VR goggles or something like that and totally make like a drone trainer or something like that Hey, there's tons of possibilities for this doesn't even need to be a drone You could hook a gun on this and turn it into some sort of drone gun battle thing All right, so there's our controls the next or the last thing we really need to do is we need to hook up the Actually, let's try the yaw. The yaw is not really working. Is it actually? good thing I Was thinking about that and that is because So this actually needs to be a value that's Declared up here. So let's do this because I need to add value onto it currently. It's just going between Four negative four. All right, so let's do private float yaw and then what yaw is going to do So we're going to constantly add onto it like so so yaw plus equals this value And basically what that means is you know every single frame. We're just constantly adding onto it You know and so this this will cause the drone to spin around, right? So let's go and take a look at this All right, let's hit play Now let's take off. So now let's take a look at the there we go There we go. So now we can really Start to fly around I'm not an expert drone pilot. I'm still getting used to it. It's actually really hard But you know This is a good way to you know train and practice You know, I've specifically set up the xbox controller because it mimics the drone controller Pretty one for one There we go. Look at that nice Cool little drone Yeah, I'm digging that. All right. So one thing you'll notice Um, we're going to take care of here. So if I were to go Right, you can see as I am moving left and right. I'm actually losing altitude and that's because Um, let's actually kind of talk about actually let's close out the lecture there And then I'll talk about it in the next lecture. Okay. Thanks a bunch