 Well, I'll come back. All right. So what we're going to focus on now is getting the tank to move around the scene Okay, so let's jump over into unity and take a look at how we're going to get this going Okay, so we're gonna do is we're gonna focus on Getting the tank to move back and forth and to rotate based off of user input. All right We're gonna use the rigid body for that. So Before we go any further with that, let's put a box collider on this Now what I like to do is I like to organize my controllers a little bit All right, so I'm gonna create a new empty game object here, and I'm gonna call this my graphics group Okay, and I'm just going to throw all of the Geometry into that graphics group and then I'm gonna create another group called the collision Group okay, and I'm going to then another empty game object Then we'll just call this main Collision all right because at some point this will have more complex collision or colliders set up for it All right, but for now what I'm going to do is just set up just a box collider for this All right, and I'm going to increase the z value here just by selecting the little Z icon or text there, and then you just click and hold and drag Okay, and I'm going to increase the x as well just till we get it roughly the size of the Tank there and then just increase that y value and Then I'm going to edit the collider so what we can do is we can interactively edit this particular collider here And to do that I'm just gonna hit this edit collider button and move this up so I'm going to go back into my orthographic view go into the side view here and Just to drag that until we get basically down to the bottom Really what I'm looking for is just to kind of encompass the whole model At least at this early stage here Go to the top view and that's pretty good actually I kind of nailed it. All right, so let's go and turn the gravity back on all right Because I want it to sit on the ground. All right, so let's go back and let's focus on the movement of the tank So I'm going to jump here into visual studio and the first thing that I want to do is I want to change over to Using the fixed update All right, so this is whenever you're dealing with rigid body you need to use the fixed update And if we come over here to the unity Documentation you can see that fixed update should be used instead of update when dealing with the rigid body And this is only because the update is called every frame and the fixed update is called at a different rate All right, and the physics need that fixed rate to work properly. Otherwise the physics are just going to go crazy Okay, you just won't have a lot of control over it. So we use the fixed update So within this fixed update what I want to do is I want to say I want to make sure first that I have the rigid body and the input so I'm going to say if Rb and Input meaning if we have both of those components if both of these variables Have a reference to in them. All right, they're not null meaning. They're not empty Okay, then we can run a bunch of code and again. This is why I like to do my custom method So I'm going to add the region custom Methods. All right and end region like so and I'm going to do another protected virtual void And we're going to call this handle movement All right And then I'm just going to call that from here. So if we have both those components I'm going to run this handle movement method And this just allows me to create different movement types So now instead of having to write all this code over again I can just inherit from the IP tank controller class and literally just update this one method or just Overwrite it and add on whatever code I want to do or completely rewrite just that method and everything will still work appropriately Okay, so it's just a you know a more Smarter way to work really at the end of the day. It's more efficient. It allows you to move faster anyways, so what I want to do now is I want to create a Variable that's a vector 3. Okay, and this variable is going to be called the wanted position Okay, and what we're going to do is we're going to store the position that the tank should be going towards Okay, so let me just put a semicolon there and explain this a little bit more So every frame or every fixed update I want to tell the rigid body I should take my current position that I'm at okay, so I'm at this current position X Y and Z right here And I want to add on Another vector all right and that vector will be this forward Direction plus a certain amount of speed okay, and so what that'll do is it'll take the current position and then add it on All right, and then the next fixed update it'll take its current position again, and then add it on All right, and we'll just keep doing that as long as the game is running or the tank explodes or you know Something happens okay, so let's get that set up and take a look We'll do a really basic example first in order to do that we need to put in some variables though So I need to say public Float we'll call this the tank speed. So this is how fast we want the tank to move. I'm just going to initialize to something like 15 okay All right, and while we're at it. Why don't we just set up the Rotation speed so we'll call this tank rotation speed We'll initialize that to something like 20 okay cool, and I also like to set up my headers. It's kind of a Knit picky thing that I always do and honestly I just can't get past not putting it in So what I'm going to do is I'm going to call this the tank or I'm just going to call this the movement Properties Okay, there we go All right, so now we have those two Float variables All right, we've initialized them to some Starting value. I'm going to come down here, and we're just going to set up a really rough example of this What I want to do is I want to say I want to take the current transform that position Plus the transform dot forward. Okay, so that transform dot forward is That little blue arrow right there. It's the best way that I can explain it It's the forward Direction that the object is looking and that is always that z direction here in unity specifically Okay, so the best way to visualize it is it's that blue arrow. Okay, that's that transform forward That's a vector. All right, it's always normalized meaning it's always a magnitude of one Okay, so it's a length of one Alrighty and I'm going to multiply that by our tank speed Okay, and though we need to do to make sure that this runs consistently on different CPUs All right and different computers We need to use the time dot delta time and I usually like to put these into the parentheses So this runs first. All right order of operations This will run first and then we'll add it on to our current transform dot position Cool All right, so let me know if any of that there was a lot of information in there So let me know if any of that doesn't make any sense, but Let's then apply it to the rigid body. So we're gonna say RB. That's our rigid body. All right Remember, that's what we're storing a rigid body. Okay, we're gonna say RB dot move position So instead of adding a force. Okay, I'm gonna move the position. All right You might have seen a lot of Tutorials out there where they're just they're moving the rigid body by adding a force now that is great when you're dealing with Something like an airplane or a helicopter Which you know I've been creating a couple courses about all that stuff or you are you know adding a force to like a ball or Maybe you're making a rocket, right? That's where you would go and add a force now You can do that with a tank But this is a basic example of how we can use this move position function. All right So if you look at the method here in the arguments, it's looking for a position Well, we just created a new position. This is a position. We want The tank to move towards. All right, so let's just feed it that position Okay, because we're constantly adding on the current position with the transform not forward times the tank speed. All right This is constantly being updated. All right, so every fixed update This is constantly being updated Okay, so let me actually just put a little comment here. We'll call this move tank forward Like so So let's check this out now. So I'm gonna come in here. We're gonna hit play and there we go So now the tank is moving forward Excellent. So now we need to actually allow the user to control that because we don't want our tank just to move off into the distance All right, we actually want some control and remember in our tank input We have this property right here this forward input right here. Okay, where we could get the current Forward input. So all we need to do now is just add another Section here just multiply it by input dot forward input All right, and we can make sure we are sure that this will run because we've already checked to see if we have the input If we don't have input Then this won't run if we don't have the rigid body this won't run We have to have both these components for this method to actually run. All right, so let's go check that out now All right, you can see that our tank is just sitting there now, okay? So if I hit the W key, we're gonna move forward if I hit the S key, we're gonna move back Easy peasy. It's simple as that That's why I like using that move position method now If you're just making simple controllers that works if you need something more realistic and you know complex I definitely recommend adding forces and adding them all up and Calculating the drag and you know, whatever you need to do This is just a great way to utilize the rigid body because I want to take advantage of the gravity component Right and velocity components. I don't want to have to calculate that myself So I get a lot of information by using the rigid body I can treat it almost like a transform that translate by using this move position All right, so let's move on to doing the rotation so we can close out this video and then move on to the next components of our tank So what we're gonna do is we're gonna rotate The tank and it's basically the same setup. So what we need to do instead of a vector for this We need to create a quaternion. All right, and now quaternions aren't actually that's that's scary per se But they are definitely confusing when you're first learning how to work with them, okay? So I'm gonna try to walk through this as best I can so what I want to do is I want to say We're gonna create a new quaternion and this is going to be called our wanted rotation Okay, and this is going to be equal to our transform dot rotation now This works because the transform rotation is work is a quaternion. Okay now instead of adding it like we do with a Vector we actually need to multiply it. All right, so this is how we can Pull two quaternions together to create a new rotation value Okay, so inside of parentheses what I want to do is I want to put in my new rotation value So I'm taking the current rotation and I want to multiply on a new rotation And to do that what we can what we can do is we can take advantage of and I actually need the parentheses there we can take advantage of the quaternion dot Euler Method all right, so if we check this out this returns a rotation that rotates z degrees around the z-axis x-degrees around the x-axis and y-degrees around the y-axis So it's got a couple of overrides, too So I'm going to provide it a vector and I like using this because I can give it a vector Instead of having to do you know some crazy math, so what I'm going to do is I'm going to say vector 3 up All right, so that's the y here, okay So that's the y position or direction excuse me All right, so that's that vector 3 dot up and let's just do a quick experiment, so I want to Then multiply this by our tank rotation speed All right, so let's just get it set up with that. I'm not going to do any inputs or anything just yet So what we can do now is you can say RB dot move rotation All right, and we'll just give it that wanted rotation All right, so let's take a look and see what happens and voila We get a spinning tank All right, and you can't actually still push forward and it's going to slowly just start to try to get out of that But it's not going to it's rotating too fast. All right, it's all based off of our rotation speed here So we could slow it down and then provide it a little bit more All right, so it's working all we need to do now is hook it up to our inputs Okay, so to do that again I'm just going to put some parentheses around this like so and we just need to multiply it by the input dot rotation input times our time Dot delta time because we need to make sure that it's mapped to different CPU speeds and GPU speeds Okay All right, so that's hooked up to our inputs now. So let's go back Let's hit play and there we go. So now we're rotating All right, we're going to need a little bit more So I'm going to put our rotation speed up to about 50. There we go All right, so at this point it's probably a good idea to set our camera up So I have the tank or the top-down camera code here So let's get that all set up. All right, so let's put in the in the main camera here I'm just going to do the IP top-down Camera and our target is our tank there And let's take our height way up and we'll take our distance way out like that. Let's hit play And that's probably a little bit too too much height Do something like that. So again, if you want to know how all this works All right, how to make the editor tools and stuff like that for this. I highly recommend watching the top-down camera course All right, so there we go. Now we have a tank and I want it to be a little bit faster So let's put this up to like 60 There we go. So now we're rotating appropriately All right, I'm gonna turn off my gizmos in here. There we go Perfect. All right, so now that I have some pretty good values I'm going to hit this little cog wheel here And I'm gonna say copy component because I'm in play mode and I want these values All right, so I want to exit out of play mode and then I'm going to then paste my values And there we go save the scene and we're good to go So I'm gonna leave you guys there and in the next Video what we're going to do is we're going to focus on getting the turret to rotate. Okay. Thanks so much