How to make a gun turret follow the mouse pointer - Unreal Engine

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to this micro lesson on how to how to get a turret to point at the direction of the mouse cursor okay so this is a very small game that i was helping out on and in this instance we have a a tank which can be moved about and the turret will follow the direction of the mouse cursor at any one point now this video is just going to concentrate on how to get the cursor to point at the mouse so all of this work is done within the tank here the actor itself so what i've done is i have used tick to update the rotation of the top section of the tank so the tank itself looks like this and this is the actual actual top whole model's made out of little primitives now it sets the rotation by first getting the player controller and getting the hit result under the cursor by channel this effectively does a uh a line trace like um from the cursor to see what to see what it's hitting along the trace channel of in this case visibility so this would give me the end point of the the channel which i can illustrate here by connecting up a draw debug sphere so if i compile that and i play you can see that the draw debug sphere is finding a location in the world and the the cannon is is pointing towards it now in order to get the rotation what i'm doing is i'm using the find lookout rotation node and i'm plugging into the top of it so the start of the finding lookup is the actor's location so that would be the the tank tank actors and then i always be using the um the the look at the end point as the output of the get hit results of the of the cursor this would give me a a look at rotation now i don't need or i don't want it to be to be an exact one or other i only really want to be updating the the rotation on the yule here so what i've done is i'll just just break these very cool pins so when you create a set world rotation you will see a box like this however if you right-hand click on it and go split pins you'll be able to drag out and guess get the singular pins itself same thing here so you can recombine and you can split split the specific pins now here i'm taking the yule and adding that in because it's only on the z yule axis that i actually want to rotate the i actually want to rotate the head so because otherwise i don't want it pointing up and down i just want to rotating on one singular axis so again this runs off tick i am just setting the world rotation of the top by using the find lookout rotation the find lookout between the get actor location and using the get player controller to use the node get hit results under cursor plugged into the target you don't need the draw debug sphere thank you you
Info
Channel: Edward Bennett
Views: 607
Rating: undefined out of 5
Keywords: unreal engine
Id: T_8Q43I9igM
Channel Id: undefined
Length: 4min 19sec (259 seconds)
Published: Tue May 11 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.