Turn In Place - Unreal Engine 4 Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys and welcome back to the mention 4 tutorial in today's video we're going to be doing a turn in place system so in yesterday's video when i made the 8-way directional movement i said that i was going to be doing a turn in place as it kind of just rotated on the circle kind of floating about so i'm going to be doing turn in place and i'm doing that today now you don't need to do that tutorial at all this can be completely independent however that's what i did yesterday so let me show you what we're going to create today so we're in we can move around with our system we made yesterday and then we can now also tighten a place so if i move the camera to the right we can turn in place like that and if i move it to the left we're going to turn again now if you don't like how the fast light is how it looks we can change the speed so i just upped the speed a little bit to test it out earlier so if i put it back down to one we should have it looking a little bit different so if i go back in it looks like that so this is what we're gonna be making today so let me delete this code and i'll show you how i've done it so the first step we want to take is we want to import our animations so i've imported some on the export from mixmo and just retargeted them to the ue4 mannequin so i'll leave a download link in description down below to the retargeted ones and i'll also leave a link to the mixmo ones now when you download them you're going to want to make sure they look like this so this might look a bit odd they're not actually turning they're just moving in a circle so make sure on mix mode they are these ones not any other ones so you don't want one like this you just want one which looks like this for both the left and right turns as that way it's going to work perfectly when we rotate the player in game as well so once you've imported the animations that's going to be good for you then we want to set up creating some booleans to know whether or not we want to turn left or right and so we're going to do that in our character blueprint so we're going to go to content third person bp blueprints dive person character for use could be first third or if you've named it in here we want to use our mouse input so our input axis turn so i'm just going to select this and just move it over here into some empty space so i have more room to do this code and i'm also just going to grab the look up and just move that down a bit so again we have some more space here and what i'm going to do is i'm going to hold down b and left click to get a branch plugging that into the add controller your input there the condition of this we just want to see if the player is moving so to do that we're going to right click and get velocity like that our return value we're going to get a vector length so vector length like that and out of that we're going to get equal equal float and just leaving it at zero so if the speed is zero ie we're not moving that boolean return value will go into the condition of the branch there so now we're only going to fire up this line of code if the player is not moving which is obviously what we want send off of true we're going to hold down s left click to get a sequence plugging that in there like so and then off of then zero and then one we're going to get some branches so we'll hold down b left click to get two more branches like so plugging them into then zero and then one like that so now what we're going to check for here is whether we're looking left or right so to do that we can right click and get turn like so just the axis value turn up there and this is just going to simply be this axis value in our input axis time here so this is going to be the value on whether we're looking left or right so out of this we want to get a float is greater than a float i'll just move these branches a little bit and this float is greater than a float is going to go into the top branch here the value in here as 0.3 so if the turn is more than 0.3 that is going to be right and then we're going to come out this again and get a less than so a float is less than a float and this one is going to be minus 0.3 so it's less than minus 0.3 we're going to be turning left and again plugging the return value into the condition there that way we now know if we're turning left or right but we also need to set some booleans so the code knows that as well at the moment we're just calculating it we need to make sure the code knows that so to do that we'll hit a plus variable here name this one turn right question mark making sure it is a boolean hit another plus variable and name it turn left question mark now if we compile this what i'm going to do to make this a bit more efficient is i'm going to make a macro so i'm going to hit the plus macro here and now we have a new macro i'm going to name this one turn right slash left question mark and what i'm going to do here is i'm going to add an input name this one in and i'm going to make it an execution pin add another input naming it turn right question mark making this one a billion like we just made these down here and one final one naming it turn left question mark and this is just more efficient because we can set both of these booleans in one simple macro instead of having to get multiple sets we can just use it in one and we'll add an output as well naming it out and making it an execution now we don't really need to do this however it's always good practice just in case so inside of this what i want to do is i want to set the turn right boolean and i'm going to set it to the turn right boolean that we input into there and do the same with turn left so whatever we input into this macro it's going to set these booleans too again making it more efficient for us so i'm going to go back to the event graph and now we can just get this macro here setting it off of true so just drag and drop there plug the in into true and we want to tick turn right and leave turn left is false so if we're not moving and we move the camera to the right we're going to make sure the code knows we want to turn right and not left then out of false we're going to set turn right to be false so we don't need to set turn left force as well so we can just do it like that and we'll do the same down here off the other branch so if we want to move left we're going to get the macro off of true ticking turn left leaving turn right as false and then we'll set turn left to be false of the false one there like so so now the code knows whether we want to turn left or right over here as well if we don't have enough speed so the fault of this branch so if we are moving we want to get to macro again plug into false making sure they are both unticked so they're both false like that so now if we aren't moving and we want to turn left or right the code knows that and if we are moving the code knows we can't turn left or right so this is that code set up perfectly so i'm just going to select this hit c to comment it and name it turn in place booleans like that whatever makes more sense for you so i'm going to compile and save that so now we're basically done in here so we can compile save and close the character blueprint and now we want to go into our animation blueprint so for me that's content mannequin animations third person and vp but for use could be first third again whatever you've named it or if you don't have an animation blueprint i do have a video on setting one up and creating one and it's just essentially where all your animations are and where the code knows to transition between different ones so it's very helpful and what we need to do tight in place and once we're in here we're going to go to our event graph and you want to make sure that you have the speed set up as well direction isn't necessary for this one however the speed is so if you don't have it you can just get the velocity the vector length and set that to be the speed again i do that in my animation blueprint video but going to do after this is we want to go up here and right click and get event blueprint begin play off of this we're going to cast to our character which for me is the third person character now if you already have a reference to your character already a cast you don't need to do this but try get pawn on it won't work as we need it to be specific to our player so we can access those booleans we just made the object will be get player character and as third person character which can simply right click promote this to a variable naming it character reference so we can access this later on back down towards the end of the code we're going to come off of our final set so our final node and get an is valid with the question mark there the input object of this is gonna be our character reference and the reason we're doing this is because this will actually fire off before the begin play because it's that quick so what it's gonna do is the first time or first couple times it fires off it won't actually be able to access the character reference which will give you some errors so this is valid just means it will only fire up this code if it can so what we're going to do is connect the character reference and get turn left and then come up again and get turn right and all we're going to do with this is right click and promote the variable naming it turn left or whatever it is for you accordingly and then on turn right right click promote variable naming it turn right and this just means we have easy access to these booleans inside of this animation blueprint as well which is what we need to decide whether to play the animation or not and to know that is that part set up as well so now we compile and save that we can start setting up the transitions and the actual animation so we'll go back to our state machine which for me is just default here you might be the anim graph so just double click the state machine there and off of our idle run state that we have here i'm going to come out and add a state naming this one turn right and i'll drag out that back into the other run so we can transition to and from there i'll come off with either one again add another state naming this one turn left again dragging back into the idle run state there so now if we double click turn right we can put our right time animation in here so i just search for turn up here i can get right turn putting that in there so when this state is active it's going to play this animation if i go back to default and go to turn left i can put in our left turn which again going to do the same it's going to play the left-hand animation when we want to that's now those are the animations set up however we still need to set up transitioning to them so that code knows when to play them so that's very simple to do as well what i'm going to do is double click on these transitional lights here so first one i'm going to do is idle run to turn right i'm going to double click that and in here this is where we can decide when it should play this animation so what i'm going to do is i'm going to get the speed here out of this i'm going to get a less than or equal to so float is less than or equal to a float i'm going to put it as one so it's essentially just if we aren't moving out of this i'm going to get an and boolean plugging that into the result and the other variable in the end is going to be turn right so if we aren't moving and we have turn right set to true we're gonna play the animation there and now in the character blueprint i did set it up so this boolean will only be set to true if we aren't moving however it's always good practice just to double check it anyway just in case so that it really won't play this animation just in case because there might be that split second where it's still true when you're moving so this is always good to just have it here as well so what we can do is we can select this and hit ctrl c to copy it go back to default so our state machine and now if we go idle run to turn left we paste this in here by using control v plug that in there all we want to do in here is drag our turn left boolean onto the turn right so now this means that if we aren't moving and we want to turn left it's going to turn left so that's perfect so if we go back to default what i'm going to do now is set up the turn right back to idle run so again i'll double click the transitional line there now this one's a little bit different so what i'm going to do is i'm going to right click and get time remaining with time remaining right turn now the return value i'm gonna get equal equal with a float leaving it as zero so this means if the animation has finished playing and now of this i'm going to get an or boolean in this other value here i want to see if we're not moving again so i'm going to get the speed and get a less than or equal to but they float again putting it as one so if we aren't moving and then we also want to have another input into this so we're going to add pin on the or and this one is going to be if we're not turning right so i'll get turned right and now this will get a not boolean so essentially if this is false plug in that in there like so and then the or is going to go into the result there so what this means is that it's going to stop playing our time right animation so it's going to go back to our normal ones if either the animation is finished playing we start moving or we stop turning right so either one of those needs to be true for this and a change so we can just select it ctrl c go to default and now if we go to turn left back to idle run control v putting this in here plug into the result again all we need to change is to turn right to turn left and the time remaining to be time remaining left turn instead so it's for the correct animation so again gonna do the same thing if the animation's finished playing or we start moving or we stop turning left it's gonna end this animation hey guys sorry about this i also forgot to mention one thing in your character blueprint what you're going to want to do is select the character movement and we want to search for rot for rotation we want to make sure that we untick orient rotation to movement and tick use controller desired rotation instead and this means that the player and the character will actually rotate dependent on the player's camera so sorry i forgot to mention earlier but this should work for you now as well so now if we compile and save this should be the code done so let's minimize and hit play to test this out you see we can walk around like normal if we're moving and turn the camera nothing's going to happen however if i am standing still and turn the camera i'm going to get our turn in place animation like so which is working perfectly for us so instead of just rotating on the spot we're actually going to have an animation for turning in place like so and if we start moving it's going to stop doing it like so or if i stop moving the camera it's going to stop turning as well so this works perfectly and again if you just open up your animations which you have you can change the speed at which they play at and you can do that by simply just increasing or decreasing the rate scale however i like this speed so i'm not going to mess about with it but i think that'll be it for this video we've done everything we want to do we've set up turner place animations so we can rotate the camera and the player will turn in place as well playing correct animations for it too so it doesn't just look bad rotating on the spot and this works with all of the other animations we set up as well however again they're not necessary to have so thanks so much for watching i hope you enjoyed and i hope you found it helpful and if you did make sure to like subscribe down below so thanks so much for watching and i'll see in the next one [Music] you
Info
Channel: Matt Aspland
Views: 96,723
Rating: undefined out of 5
Keywords: ue4, unreal engine 4, unreal engine, tutorial, ue4 tutorial, unreal engine 4 tutorial, how to make a game, how to, 3d modelling, blender, unity, games design, graphic designer, ue5, unreal engine 5, turn in place, ue4 turn in place, anim, anims, animation, animations, turn, right, left, camera, follow, move, turning, moving, movement, walk, walking, look, up, down, yaw, pitch, roll, circle, loop, not working, broken, unreal engine turn in place, advanced, locomotion, directional, direction, movements, how to turn
Id: 3zVh1-4zmy4
Channel Id: undefined
Length: 14min 9sec (849 seconds)
Published: Mon Feb 22 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.