Aim Assist in Godot (tutorial)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys so i got a quick tutorial for you today and godot um i'm going to show you how to implement aim assist in uh your first person shooter or your third person shooter game um in this case i have a first person shooter set up uh so let's go ahead and get kraken so for a lot of good old users you probably use mouse and keyboard exclusively but i know that you'll want to uh probably also add controller support and frankly i know that personally my con my uh my control uh my controller skills are not up to snuff uh without aim assist so i'll show you how to do that today so i'm gonna walk you through my script here that is for my uh player right here and let's make sure that we see everything so i have everything under physics process i know this is bad because of uh like uh you know you can't go above 60 fps essentially which is uh crucial for any sort of uh fine-tuned aiming but i'll keep it like this and think it's supposed to be fixed and good o4 as well so uh just to bear with me on this but uh yeah so i have some basic ground logic i have a ground ray that points down towards the ground make sure it's grounded and i get the i calculate my gravity based off the ground normal or just going down period so you probably have seen this before but this is to make sure that your character can climb slopes and stuff all right and so now this is basically the rest of this is locomotion so i have a look input function that will return a vector 2 of my uh my look axes on my right stick and then i have the same thing set sort of thing for my move input which is on the left stick so that's kind of walking you through that and then the very next thing is aim assist here so this is all i do for aim assist all right so i have in my 3d view i have a look ray which is right here hopefully youtube compression doesn't completely murder this but it's looking straight ahead and it's aligned with the camera i also have the for my fps controller here i have a camera helper which basically controls the uh vertical rotation of the camera and makes sure that everything's good to go on that and i don't have you know if you want to animate your camera shaking or something like that you can do that without having to worry about calculating that in uh when you uh you know are looking around so keep that in mind um so i have a look ray pointing directly where my camera is pointing and if that is colliding i tell another ray which this can be either array uh so here's my here's my aim assist ray uh this can be an array or it can be something that has any sort of rotation so you can't just use a spatial node which kind of it's kind of unfortunate um or are specifically a position 3d node and then i prefer using a raycast so they actually have a visual indication of where it's pointing and that's because it's it's going to be rotating towards the uh the looking the look target over here and so uh once that you know uh once that has uh right yes right here so once that's looking at the uh the look ray's collider which is basically what is what's what it's hitting it's looking at the origin of that object and this is just kind of an offset that helps it you because sometimes you might have some mismatch between what is you know uh transform dot uh forward or or vector three that forward for one object versus another and so i had to adjust that so don't really worry about this line too much you you will probably have to tweak it for whatever implementation you use um and then one thing i do uh if i is that if i am actually looking at a an enemy player i will divide my looking vector which is you know once again this is for my my user input on the right stick i will divide that by 1.5 just so that it kind of slows down a little bit and that's where you get that kind of uh this motion here where it kind of stops for just a split second and then resumes you know at full speed so that's kind of what's going on there make sure i'm zoomed in for you guys uh and then for the the player models rotation which is uh under the kinematic body i basically uh interpret interpolate the angle um make sure you use lerp angle and not just lerp because that can uh that will help you avoid a lot of headache with uh translating that but uh uh we uh interpolate our rotation.y and look at our aim assist rotation.y remember our aim assist is looking directly at the the other collider so um you want to make sure it's kind of slowly looking towards that and you might have to add your own rotation to it you know because this is a child of the player right here if you look at my aim assist ray it's a child of player as opposed to as opposed to a child of cam help so uh you'll want to make sure that you have everything you know all the logic down on that uh and then as soon as that's done you want to also interpolate your camera's rotation uh to match the aim assist rotation and in this case i had to make it inverted just sometimes you know it's going to be a little bit nastier than you want it to be but um considering that this is only five lines of code to basically implement aim assistance you know i think it's a pretty good trade-off um and then otherwise i just set my aim assist rotation to zero um that's just you know default you know i don't want uh it being everywhere you know i want it to be nice and clean and then after that i basically have my uh my other you know rotation logic which is you know if if we're not hitting anything then this would this would be what what executes is you know basic rotation you know hopefully you know how to do this um and then you know you clamp your x rotation to be in between 90 and a negative 90 and 90. so now when we play this this is what happens so this red object here is the enemy player i know it's a you know very very complex here but as soon as that that look great collides with it you see how it kind of snaps into position and i can kind of move around a little bit and i can escape that if i you know hold down my my right stick long enough uh i wish i had a visual input of my right stick but um but yeah you should be able to get the picture of what's going on here it's just kind of slowly tracking towards the center and then it will also slow down your your your look view you know your your uh your look sensitivity essentially um and uh yeah and this still works relatively okay with uh movement as well um and so you'll see that it also kind of track with just a little bit with movement i know it's kind of probably hard to uh visualize uh via video but uh in game you'll you'll feel it so but yeah you know this is about about five lines of code to really get aim assist working on on uh and godot so hopefully this is useful for your project um if you have any other questions or any suggestions for improvement please let me know anyway have a have a great one everybody
Info
Channel: Toadile
Views: 277
Rating: undefined out of 5
Keywords:
Id: vpf8jBVSnUE
Channel Id: undefined
Length: 7min 35sec (455 seconds)
Published: Fri Aug 13 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.