Unreal Engine - Making your character look in the camera's direction (My Simple Method)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys i'm back with another video so i thought i would do my own uh method on looking from left to right and uh so i'll show you how i did that and uh actually i this one kind of snaps but we're gonna fix that in the one that i do so you can look up and down as well so let's get started so first off you're going to create a new third person uh example template project and then you're going to go under the blueprints and you're going to right click and you're going to go to blueprints and blueprint interface you don't really need to do this part you can skip it if you want to but i like to do this because i think it's best practice to get in the habit of doing things properly so just open up that after you've made it and we're going to call this essential values kind of an als naming convention but i like it so i'm going to use it so right here we're going to call this aiming rotation and we're going to select rotator here we're just compiling and save it we're going to open this one up and then here let me do this real quick because uh this guy is not going to stop so uh over here what we're going to do is we're going to go to class settings and we're going to go to add and we're going to select that bpi char info that we created and if you can't find it type it in here bpi char info but you have to i guess it's case sensitive anyway so come over here and just double click on this under interfaces expand that tree and double click essential values we're going to get this and we're good we're going to drag off of it and we're going to say get control rotation so after we've done that save it exit out of that go to mannequin animations and open up third person nmbp so under this what we're going to do is we're going to drag this one out we're going to promote this to a variable and we'll just pull this out we'll go ahead and create our our two functions as well the first one is going to be update char info and the second one is going to be uh uh update looking angle and then we're going to go back over here and we're going to drag these off of here first we want to update our char info and then we want to update our looking angle so after you've done that right click up here and type in initialize animation right here blueprint initialize animation i want to control x that and paste it right here the try get pawn owner and off of here we're going to cast to a general character class which uh will give us access to anything that's that has the character as its parent class then we're going to promote this to variable i'm going to call this char ref you can call it whatever you want we're going to drag this out onto these nodes here anywhere basically that try get pawn owner was connected so first we're going to come into here the update char info we're going to drag this out we're going to get it we're going to type in essential values it'll have a message in uh uh parentheses right there so we can just drag this over here like this and promote this to a variable aiming rotation that's fine so [Music] under update looking angle we're just going to drag this off and what we need to do is we need to get the angle between where the character is looking and we we're going to get the angle between where the character is looking and where the character is facing so get your char reference and pull off of it and type in uh get actor rotation right here so let's plug this into our delta and if you didn't see me what i did earlier i just typed in delta off of this it's a delta rotator and so off of this we actually need to split that and off of our y we're going to divide it by negative 2 and the reason why is because we're going to use to modify transform bones and the values that were the rotator that we're making from this needs to control both of them so we're going to divide it by the number of transform modified bones that we're doing in this case this is the look up and look down function so when your camera is pointing down it's actually uh going to be a positive and when it's uh when you're looking up it's going to be a negative so we want that to be inverted and so that's why i'm dividing by negative two on this one so off of this one we're just going to divide again but we're going to divide by two this time and uh also let's see yeah we're going to uh clamp these angles and i'm going to clamp it between negative 50 and 50 for me i've already printed these values out you can just hook up a print string to them to see what kind of values you're getting and uh set the values according to your own needs if you want him to look farther back then that's fine you can do that you can even add more transform modified bones if you want so over here we're just going to create another variable we're going to call this uh look angle uh looking angle and i'm going to make this a rotator and then we're gonna set this we're gonna split it we're gonna connect this up to the x actually and this up to the z and the reason why is because uh uh for these bones the x is actually going to be uh the up and down uh because we're using we're gonna use component space so we're going to connect this up to here for now and there's one more thing we need to do off of this one we need to get the z or the left or right and what we need to do is we need to get the absolute value of that because this is if we go to a top down view here not sure how well you can see that there we go so when you rotate clockwise or in this direction it's going to be positive and when you rotate in this direction it's going to be negative so it's 0 to negative 180 and 0 to 180. so we want to say for me i'm just going to use i'm just going to say if this absolute value is greater than 150 uh then we can look so i'm going to promote this to a variable i'm just going to call this can look and i'm gonna drag this over here and i'm gonna hold down control and and pull this one over here and drop it on here and then i'm gonna do that and then we need to duplicate this looking angle and i'm going to call this smooth looking angle and if we don't do this then the then it'll be jerky so what we're going to do is we're going to set that and we're going to drag it out i held down control to drag it out as a getter so off of this one we're going to do an r and terp 2. and this basically it just uh is just slowly over the over time it will uh interpolate from this current location to our target location our target location is our looking angle and then we need our delta time and for me personally i found a value between 10 and 15 to be fine but for this i'm just gonna i'm just going to use 10. uh the higher the value the faster it'll interpolate and the choppier it'll be the slower the value the smoother it'll be so with that being done that's pretty much it we're almost done so we just need to do some stuff on the anim graph now so let me drag this back over here so you can see better so for the default pose we want to catch this and what this does is it allows us to store this uh pose temporarily so we're gonna call this default pose and the reason why is because we need to blend it twice and you can't have one of these uh connected to two different places and that's the reason why we have to catch it so off of here we'll type in default pose and you'll see a use catch pose default pose that's this one so we're going to duplicate that twice because we're going to need it twice and off of this first one we're going to do a blend and we're going to change this from a float to a bull value and when we do that that also gives us this blend settings option right here and what we're going to do is we're going to set this to let's say 0.3 and 0.3 you can try 0.2 or whatever you can play around with it but that's just the the blend in and out time again if we don't have that we're going to get choppy animation movements so that's the reason why we're doing that can look that's what's going to control this now we're going to create our animation layer we're going to call this look to camera and now uh we're going to add an input over here under the details if you don't see it select this just click on it and then it'll pull up over here under the details add your input pose and then right click and add a modify or a transform modify bone and before we duplicate this let's unpin these so just press the expose this pin and and click that and then on this one we're going to add to existing rotation and we don't need a float value so we're going to unexpose that as well and then now we can duplicate this we're going to connect this one up here and this one up here and then we're going to connect this one right here and i'm just selecting the first one into the second one and i'm pressing q now we're going to drag this smooth aiming angle out and then connect it to the rotation now for this we want the first one to be neck so type in neck and get your neck one bone and for this one we want it to be head so we want to get our head bone and now we have to right click here and type in linked animal layer right here select it and then go to the layer under the details and select look to camera we're going to connect these and connect that and then compile it save it and that should be it so now uh okay i did something wrong there so let's go back in here let's see it must be right here where i'm doing this at let me open up this other one and see if see what i did wrong here did i use a less than no i did not i used a greater than that's the issue we need to do less than here i'm not sure if i told you to do a greater than i may have but we need that to be a less than so that's that was the problem so now you can see we have him looking down up left right and he has a smooth transition from one side to the other and you can move it back and forth real fast and it won't get jittery or snappy or uh jelly like that was the issue i had so i had to figure out why it was doing that it was just the way i was doing my interpolations i did the interpolation on their own thing so uh all right that's that's pretty much it so i hope you all guys like this if you found it helpful then uh please don't forget to like and uh subscribe and uh you know maybe hit that notification bell so alright thank you
Info
Channel: Unreal DevOP
Views: 11,025
Rating: undefined out of 5
Keywords:
Id: 3hy7Oh7r64E
Channel Id: undefined
Length: 14min 20sec (860 seconds)
Published: Tue Feb 08 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.