 Alright so we are almost done with our basic tank controller so what we're going to focus on in this video is getting the turret to face wherever the position of the reticle is. Okay so why don't we just take care of the reticle and the turret in this same video because it'll just make it more sense and because positioning the reticle is actually quite simple. So let's jump over into Unity and get going. Okay so let's start by getting the reticle to be positioned wherever the cursor or I'm sorry the input dot mouse position is or the little cursor here in the game view. Okay so I'm gonna jump back over into Visual Studio and what I want to do is create another method here called handle reticle like so. Alright and in order to move the reticle let's actually set up this method first so I'm going to do another protected virtual void and let's just copy it so we don't have to type it in. Alright there we go and in order to move the reticle we need to get a reference to the actual transform that the reticle is or the game object. Okay so I'm gonna create another header attribute here we're gonna call this the reticle properties. Now you could always put this in the input script as well but in this case I'm gonna put it in the controller script. You know it's a toss-up whether or not you know one is better than the other so I'm just gonna put it in the controller class here. Alright so I'm gonna make this a public transform and I'm just gonna make it a transform that way don't do you know if if I were a game object then I would have to you know look for the transform so I would say something like you know transform dot or you'd say something like you know game object dot transform right dot position in this case I just want to say transform dot position kind of deal okay so what I'm gonna do is call this the reticle transform like so. Alright so I'm gonna copy that so I don't have to type it and we're gonna say if we have that reticle transform then we're simply going to say that the reticle transform dot position is equal to our input dot reticle position. Alright we set all that information up so with that all set up let's come back in the Unity here and hit play. Alright so now the reticle should be placed wherever the mouse is but we need to actually assign it. Alright so I'm a little off my game right now so let's drag and drop the reticle there and hit play again. There we go so now the reticle is being placed wherever the mouse cursor is. Cool. Alright so let's get the turret to point towards that reticle position alright so I'm gonna jump back into Visual Studio here and again I'm gonna create that protected virtual void and again I'm doing this that way I can override any one of these particular methods in a different script without having to rewrite the whole script. Okay we're gonna call this handle reticle and you probably see a little pattern starting to form. This is basically what I like to do and it's not handle reticle we want to do a handle turret. There we go. Alright so I like to break out all my components or script components that's not even a good way to put it. I like to handle or break out all my functionality into these kind of componentized methods instead of having you know these massive methods I've seen a lot in Unity projects. So I'm gonna put that right there so I'm gonna handle the turret and then handle the reticle. Now you could move these around however you want you know it's it's not really an issue at this point. Alright so for this now we need to get the turret transformed so I'm gonna create another header up here and we're going to say turret properties like so and I'm gonna say public transform and we're gonna call this the turret transform like so. Pretty easy stuff. Alright so now if we have that we're gonna say if we have that transform. Alright so if it's populated with something okay then what we're gonna do is we need to get a direction from the turret transform alright from its position to the reticle position. So in order to do this we need to make a new vector three and we're gonna call this the turret lookdir. Okay so for look direction right now it's gonna be equal to our input dot reticle position remember that's the position where the mouse is okay minus our turret transform dot position okay cool so that basically creates let's come back in Unity and try to visualize this so what that does is it creates a direction that points towards the reticle alright so it takes the current position of the turret right over here okay and it points it towards this and we can use that information alright so let's see how we use this information now. We can use that information to create a look direction alright so we're gonna say that the turret transform dot rotation is equal to a quaternion dot look rotation and we need to provide it a vector and this vector is that turret lookdir so we're gonna say turret lookdir like so alright so let's take a look so this isn't gonna work right off the bat but I want to show you how to debug different types of issues okay so let's go and assign the turret so I'm gonna come in the graphics group here and get this turret group because this is what I want it to rotate on okay so I'm gonna assign that turret group that's that transform into that turret transform property alright so let's hit play here and you'll notice that we are getting it to rotate and actually it is is it it's totally working isn't oh no it's not totally working see how it's actually kind of pointing towards it now you might like that that's not how tanks really work now in a cartoony situation or stylized type of game maybe that's you know how you want it to work but I want the gun to rotate up and down and the turret to rotate left and right so you can see that it's you know not working totally right so all we need to do super easy fix come into visual studio here we need to take the current turret look there all right we get that y component because currently the y component has value in it okay so I come back here into unity I'll try to you know visualize this for you guys a little bit more alright so if this gets really close you can see that you know the position of the turret head to the reticle would create a direction that points downwards and that's why the turret head is actually looking down towards the reticle so all we need to do is remove any y information that we have so we're just going to set it to zero all right super easy all righty so let's go and take a look and see what that looks like now so I'm going to play all right so perfect so now you can see if I get the reticle anywhere near the tank it doesn't look down at it we want the gun to just look down at it all right so that's what I wanted all right so the next thing that I want to do before I close out the video is just put a little bit of lag on the turret head there so I'm going to come into the visual studio IDE here and I want to put in a public float so we're going to call this the turret lag speed and I'm going to set it something like 0.5 all right okay and I also need to create a private variable this is going to store that final look direction and this is going to be a vector 3 so it's going to be the final turret look there you'll see why here in a second so I'm going to copy that come back down to our handle turret method here and right before we assign the look direction to our transform dot rotation I want to say that the final turret look there is equal to a vector 3 dot lerp we want to go from the final turret look direction so whatever that is currently set to to our wanted or our turret look there sorry by times dot delta time times our turret lag speed okay so what this is going to do is it's going to create a little bit of lag because the final turret look direction this vector 3 right here is going to be constantly trying to catch up to the actual turret look direction that we're calculating up here okay let's go back in a unity and check it out all righty so let's go and hit play now all right and it's it's pretty hard to see right now so let's go back up to our tank and let's set our lag speed to something like 0.02 and see what happens and I forgot to assign the final turret turret look direction to our look rotation so there we go so let's go back in unity here and hit play and there we go so now we're getting a nice lag perfect so it's a little slow actually you can maybe pump it up to like point 1.2 let's see what we get it's still pretty slow let's put it up to like 3 there we go maybe 5 yeah you can play around with all these values as much as you like let's say 10 there we go that's feels nice and arcadey enough but still has a little bit of fun to it maybe like 8 there we go cool all right so I'm going to call that good remember you know after you are setting values while in play mode just to copy the component that you've been working on come out of play mode and then just paste those component values and now you're set okay so I'm going to leave you guys there and in the next video what we're going to do is just set up the post effects by taking a look at unity's new post effect system that's still in preview and then we're going to call it good all right thanks so much