How to Make a 3rd Person Character in UE5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
when you launch Unreal Engine 5.1 for the first time and try to understand the default third person template it can be quite overwhelming because of all the things that come into action just to make this small template work and to help you better understand how this all work I created this tutorial in which I'm going to teach you the basic of Unreal Engine 5's character blueprints animation Blueprints and enhanced input system so that you will go from knowing nothing about these systems to being able to easily set up a playable and animated character from scratch for your own ue5 project and for this tutorial I'll be using the default third person template from which I've changed the skin of the character to my own Tiki robot but if you are working on your own game you can use your own character as long as you have an idle animation a jump animation a run animation and a for Loop animation for when the character stays in air okay so the first thing we are going to do here is create a blueprint that will Define the visual appearance of our character as well as its movements and to do so I'm going to press Ctrl space on my keyboard then I'm going to right click in the browser and select blueprint plus here under Engine 5 is asking me to choose a base template that I want to use as a foundation for my new actor I'm going to select the character class which is available right here because it has a lot of built-in features for creating characters I'm going to rename this new blueprint to BP underscore hero and then I'm going to open it so here the character template provides a starting point for our actor including a list of components that you can see here on the left side of the screen each of these actor components that you can see as building blocks for our character search a specific purpose such as handling Collision for the capsule component or showing the fourth direction for the arrow component but the actual component that I want to bring your attention on is the mesh component because it will help us Define the visual appearance of our character and to define the visual appearance of my character I'm going to go here on the right side of the screen in the details panel and then I'm going to change the skeletal mesh asset parameter to my custom character which is the just you know if you're working with the default third person template you can select the skm money simple or skm Quinn simple so here I'm going to set it back to my SKT key and since I want my character to be aligned with the caption I'm going to drag it down a bit so that it's fit are aligned with the bottom part of the capsule minus 90 yeah it seems okay okay so now since I want to make the capsule better fit the size of my character I'm going to select it and here I'm going to change its half height to 90 so that it becomes bigger and I'm going to change its radius to something like let's say 30 okay and finally since this Arrow component is supposed to show the fourth direction of my character I'm going to select my mesh component I'm going to click here on the rotation Gizmo and then I'm going to rotate my character 90 degrees counterclockwise so that it looks in the correct direction okay so that's great and now that the visual appearance is done I'm going to tell Unreal Engine 5 that I want to control this character when it's placed in the world to do so I'm going to click on plus default right here then I'm going to type here in the search bar the word process and I'm going to change the auto process player parameter to player 0. I'm going to compile save and here I'm going to go back to my viewport and here if I drag my character by pressing Ctrl space and selecting my character then dragging it in the world okay so it's here in the world if I press play I should take control of the character and press play right here and it doesn't work because our character is not appearing on screen okay yes so contrary to what you might think the problem does not come from the character itself but from the camera which is inside the body of our character and to verify that what I'm saying is true all you have to do is click on the eject button right here to reject yourself from the game then move the camera backward to see that you were inside of the character and since we are not making a first person game we are going to find a way to make it so the camera sits behind the character at all time and to do so I'm going to press stop right here to stop the game then I'm going to go back to my BP hero and here in the components tab I'm going to click on the add button type spray ring and select the spring arm to add a spring arm component to my actor so here the spring arm is the red line that you can see right here and you can see the spring arm component as a selfie stick to which we are going to mount a camera so that it can constantly look at the player but before doing so I'm going to select my spring arm component press f2 on my keyboard and rename it to selfie stick so that I won't forget what it's used for here I'm going to press compile and now to mount my camera on my selfie stick I'm going to select my selfie stick click on the add button type camera and select camera okay so here I've added a camera component to my blueprint and if I press play you can see that our camera is placed right behind the player just like in a third person game but before moving on to the next part of the tutorial I'm going to adjust the view of the camera by selecting my selfie stick then I'm going to go here in the rotation part of my selfie stick I'm going to type -10 in the y-axis sorry so that it will go a bit up and then I'm going to move it 30 unit along the Z axis and reduce its Target arm length to 250 so that the camera gets closer to the car there now if I press play you can see that the camera is closer to the character and at the more interesting angle but here no matter what key I press on my keyboard the character won't move okay so now I'm going to teach you how to set up the enhanced input system of Unreal Engine 5 so that will be able to listen to player inputs and make the character reacts accordingly and to make this system work the first thing we need to do is Define the actions the player can make in our game and create an input action as set for each of these in our case the game is pretty simple since all the player can do is jump move around and look around and to begin with I'm going to create an input action for the Jump by pressing Ctrl space on my keyboard right clicking in the content browser selecting input then input action then I'm going to rename this new asset to inp for in put underscore Gem and open it so here since we are just getting started with the ue5's enhanced input system we won't bother looking at all the parameters available to us instead we are just going to focus on one specific parameter the value type parameter which defines the type of input that will be used to trigger the action we are currently setting up so this value type parameter can be either set to digital if the input is a button that can be pressed or released or accessed 1D 2D or 3D if it's a joystick or something similar that can move around one two or three axes in our case since the player will jump by pressing the space bar or button on his Gamepad we are going to leave this parameter to digital so that's all we have to do for the jump action we can save it and close it and now we are going to create the input action for moving the character around I'm going to press Ctrl space I'm going to right click select input then input action and here I'm going to rename this new asset to inp underscore move around then I'm going to double click on it to open it so here since the player is going to move the character with a joystick or with the w a s and the keys we are going to set the value type parameter of this input action to axis 2D here so that our game will be able to support movements along the X and Y axis so now I can save it and close this and on to the creation of our final input action that will be responsible this time for making the character look around with the camera and since this action is going to be working with the joystick it means we have the same settings as the input action we've just created from moving around so to facilitate the creation of our last input action I'm going to select the inp move around press Ctrl D on my keyboard to duplicate it and then I'm going to rename this new input action to inp underscore look around and voila we've just finished defining the three input actions of our character so now let's create and all but now that we've defined the actions the player can in our game how do we bind them to the keyboard and mouse or Gamepad inputs this is where the input mapping context of the enhanced input system comes into action to put it simply an input mapping context allows us to Define which keyboard mouse or Gamepad keys are bound to each of our available actions in a specific context of course in this tutorial since you are making a simple prototype we won't be using this system to its full potential and we are just going to create a single input mapping context but just so you know in a game like GTA for example the input action mappings will vary based on the context in which the player actually is for example if we take the right trigger of a Gamepad in the context of the player walking around the trigger will be used to fire projectiles while in the context of driving a car it would be used to accelerate so now let's create the input mapping context of our game and here I'm going to press Ctrl space right click then I'm going to select input and input mapping context okay okay so here I'm going to rename it to IMC underscore third person and then I'm going to open it so first I'm going to set the mappings for the Jump by clicking on the plus sign next to mappings right here and here I'm going to select the inp jump in the drop down menu if you are following this tutorial with the default third person template just so you know please make sure that you've selected the inp jump asset that we created earlier and not the Ia jump that is available by default with the template okay so here I'm selecting the inp jump and now that I've chosen the action that I want to set up I'm going to bind the space bar to it by selecting it to the drop down menu here I'm going to type space bar or if you want you can just click on this small keyboard and press on the key that you want to assign to the jump okay so since I'm also going to play with the GamePad I'm going to add another binding by clicking on the plus sign next to the inp jump and then I'm going to select face button bottom here I'm going to select this one face button bottom to bind the a button of my Xbox controller to the jump so now that our first mapping is set up and before moving on to the next ones we are going to set up our character so that it can use our input mapping context to Trigger action events based on player inputs so here I'm going to press save I'm going to press Ctrl space on my keyboard I'm going to open my BP hero and here I'm going to go to my event graph and I'm going to add a bit of code to make my input mapping the default one so here I'm going to go to the event begin play I'm going to drag is valid node then I'm going to right click type get player controller I'm going to drag an enhanced input local player subsystem this one then I'm going to plug this into the input object of the is valid node and then I'm going to drag a wire and type add mapping to select add mapping context here I'm going to connect this to the is valid node and here in the mapping context I'm going to select my IMC third person so now that the input mapping context is defined we can add an event that will be called every time something happens with the key assigned to the jump action so here I'm going to right click and type jump and I'm going to select inp jump okay this one not the Ia jump but the inp jump so this event has a lot of parameters but in this tutorial we are going to focus on the trigger parameter which is launched every frame as long as you hold the key down started which is called once as soon as you press the key down in my case the spacebar and completed which is triggered when you release the also there's this action value parameter which here will be equal to True when the key is pressed and false when it's released so here to better visualize the behavior of this event I'm going to add a bit of code and hear the trigger I mean to drag a wire type print string and here I'm going to select it press Ctrl s d on my keyboard plug this started in this second print string and the completed in the same print string then I'm going to plug the action value right here and so here if I launch the game when I press the space bar it should be set to true it should print true when I release it it will print false and as long as I hold the space bar down it will print hello so here if I launch the game and press the space bar for a short moment then release it you can see that it printed through okay and false when I released okay yeah so now that we are done setting up our first input to action mapping let's move on to setting up the one for moving around and to do so I'm going to go back to my input mapping context and add a new mapping by clicking on the plus sign next to mappings and selecting the inp move around input action that we created earlier so here if you remember well earlier in this tutorial we set the value type parameter for the move and look around input actions to access 2D instead of Boolean like the jump in order to register to the inputs from a thumbstick and since the input action event is going to work a bit differently from the jump event we're going to do some testing first to better understand how these kinds of input actions work to begin with I'm going to bind my Gamepad left thumbstick to this action by clicking on the drop down menu typing lower 2D and selecting Gamepad left thumbstick to the axis from the drop down menu okay so then I'm going to go back to my BP hero and add a move around input action event to the graph so here I'm going to right click type input action move around and I'm going to select the enhanced action events input move around so here you can see that the only thing that differs from the jump event is the action value parameter which is of type Vector to the structure instead of Boolean now we are going to connect a print string to the triggered bin print string and plug the action value in the in string parameter to see how this action value works so here I'm going to compile press save I'm going to grab my Xbox controller and then I'm going to press play so here if I tilt my left thumbstick left and right we can see that the x value changes from -1 when it's tilted all the way to the left to one when it's tilted all the way to the right okay on the other hand if I tilt my thumb stick up and down it changes the Y value from -1 when it's tilted all the way down to one when stitching all the way up okay so that's great so now that we know how access to the input actions work this will be useful for the next section in which we are going to bind our keyboard keys to them okay yeah so now we are going to simulate the behavior of our thumbstick using four keyboard Keys w a s and d and to achieve such a thing we are going to bind each of these keys to a specific tilt angle of the thumbstick for example when we'll press W key on our keyboard This Will simulate the stick being tilted up while pressing the a key on our keyboard will simulate the stick being tilted all the way to the left and to begin with we are going to start with the G key because it's the easiest one to set up to do so I'm going to go to my input mapping context then I'm going to click on the plus sign next to inp move around after that I'm going to click on the small keyboard and press D on my keyboard to bind this key to the input action now if I go to the viewport and press play to see what happens you can see that if I press the D key on my keyboard everything works correctly since X and Y are equal to 1 and 0 respectively which indeed simulates the stick being tilted right now what about the a key let's go back to our input mapping context and bind the a key to the move around input action by clicking on the plus sign right here clicking on the small keyboard and pressing a on my keyboard then if I go back to the viewport press play and hold the button a down you can see that we have a problem since pressing the 80 sets the X to 1 instead of -1 to solve this issue we are going to use an input action modifier which is used to as its name suggests modify the value outputted by any of the keys bound to an input action to better understand how it works let's add a new modifier to our a key binding by adding an element here and clicking the plus sign and adding a new element to the modifiers array here if you click on the drop down menu you can see that there are a few modifiers already available we are going to select the negate modifier to be able to negate the value that comes out when we press the a key okay so here I'm going to select the negate and now if I go to the viewport and press save go to the viewport and Press Play If I press the a key now you can see that value of x equals -1 instead of 1 which is what we are looking for okay so now we are going to set up the W key binding so that it can simulate that thumbstick being tilted up to do so I'm going to go back to my input mapping context add the new binding by clicking on the plus sign right here and then I'm going to click on the small keyboard and press the W key on my keyboard so here to simulate the vertical inclination of the thumbstick we are going to add a swizzle input axis value modifier so here I'm going to go to the modifiers I'm going to click on the plus sign and select the Swizzle input axis values that will help us swipe a swap sorry the values of X and Y so that we can modify the value of y instead of X when the key is pressed so here if I unfold the details of the modifier you will see that everything is set up as it should since the order y x z means that the value of X and Y are swapped now let's go back to the viewport press play and if I press the W key you can see that it works since it's the value of the Y parameter that changes when I press the W key okay that's great and now I'm going to bind the last key which is the S1 by going in my input mapping context clicking on the plus sign next to the move around input action clicking on the small keyboard and pressing the S key on my keyboard to bind it to the move around action so here we know everything we need to know since all we need to do is combine the two modifiers we've already used first I'm going to add a modifier Swizzle input axis values to swap the X and the Y value and then I'm going to add a negate modifier so that when I press this key the Y will equal -1 instead of one so here if I press save I can go back to my viewport and now oh just a quick note now that I think of it before we test it modifiers are applied in the order they appear in your array so here when I press my S key it will apply first the Swizzle input axis values modifier then it will apply the negative one okay so in our case the order doesn't matter since it will give the same result but it's important to know that when you want to create more advanced input mapping context later so now let's go to my viewport press play to try it out and there you go if I press my S key you can see that the Y equals minus one okay so now we are going to set up the look around input action and to do so I'm going to go back to my input mapping context right here then I'm going to add a new mapping by clicking on the plus sign and then I'm going to select the inp look around here I'm going to bind my gimpads right thumbstick so I'm going to click on the drop down menu type 2D and select Gamepad right thumbstick to the axis then I'm also going to bind my mouse I'm going to click on the plus sign right here to add another binding then I'm going to click on the drop down menu and type X Y to select the mouse XY to the axis okay so once the inputs are mapped I'm going to go back to my BP hero here I'm going to disconnect this logic by pressing the ALT key on my keyboard and left clicking on the triggered pin and here I'm going to right click type input action look around and select the enhanced action events input look around here I'm going to select this press Ctrl D on my keyboard to duplicate it connect the action value here and the trigger here so that we can check if everything works correctly so here if everything works as intended tilting the thumbstick up down left and right should give the same result as moving the mouse up down left and right so let's check it out I'm going to compile save press play and here if I tilt the stick from left to write you can see that X goes from negative to positive on the other hand if I move my mouse from left to right it does so too so we can see that horizontal axis movement is working as X expected however if we test the vertical axis Movement we are going to see that there's a small problem indeed if I tilt the stick from top to bottom y goes from negative to positive whereas if I move the mouse up and down y goes from positive to negative I don't know if you'll see this because it happens really fast but you can trade for yourself and see that what I say is correct so here to create this we can either invert the gamepad's vertical axis or the mouse is one we are going to invert the ladder by going back to our input mapping context and adding a negate modifier to the mouse X Y to the axis so here I'm going to click on modifiers I'm going to select the negate modifier and then I'm going to unfold the details of the modifier because all I want to do is negate the y-axis so I'm going to uncheck the x and z parameters so that only the axis will be inverted by the modifier now if I launch the game and go here and I launch the game you will see that if I move the mouse up wait goes negative and if I move the mouse down the Y goes to one okay so now that our inputs have been set up we are going to implement it to the gameplay logic of our character by starting with the jump and to do so I'm going to go to my BP hero then I'm going to focus on my input action jump so here as I said earlier in this tutorial the character class comes with a lot of built-in functionalities and the jump is no exception to that here I'm going to select this bit of code and I'm going to drag a wire from the started pin and type jump I'm going to select the jump here and here we go we've created our jump functionality so the jump function is a built-in function of the character class and here if I compile save and launch the game you will see that if I press the spacebar the character jumps so now I want to tweak the jump a bit so I'm going to go to my BP hero and select the character movement component in the components Tab and then I'm going to go to the details Tab and search for the jump following category so here character movement Jam following category here I have access to all the parameters related to the gem for example I'm going to increase the height of the Jump by setting the jump Z velocity parameter to something bigger like let's say a 800 centimeter per second and I'm going to launch the game and here if I press space you can see that the character jumps higher now since the jump is a bit too floaty for my taste I'm going to make the character fall Faster by typing gravity here I'm going to type gravity and then I'm going to increase the gravity scale to something like like 1.75 for example and here if I launch the game you can see that the jump is much better now okay so that's great and all but what if I want to make the character jump higher when the player holds the button longer actually since it's already implemented the character movement it's quite easy to achieve to do so first I'm going to drag a wire from the completed pin of the input jump action event and then I'm going to type stop jumping and add a stop jumping node by doing this Android engine will stop making the character go higher as soon as I release the spacebar now if I launch the game you will see that it doesn't seem to work since the character jumps at the same height even if I hold my space bar longer actually this is due to the fact that as long as we don't tell anuel engine that the player can hold the jump button down it will consider that the player is always just tapping the button even if you are pressing and holding it down to activate the ability to hold the jump button down we need to change a property in the character class to do so I'm going to click here on class defaults and then in the search bar I'm going to type jump hold and set the jump Max hold time parameter to something like a 0.5 to tell annual engine that the player can hold the jump up to 0.5 seconds if you want to jump higher so to be more precise by doing this a vertical force will be applied to the character to make it go higher as long as the player continues to hold the button down but it will only be applied for a maximum of 0.5 seconds after that the force will stop being applied even if the player is still holding the button down so here if I launch the game we can see that if I tap the button it jumps at a certain height and if I maintain the button down you will see that the player jumps higher so now the player is jumping a bit too high for my test so I'm going to change the GMC velocity parameter up here I'm going to click right here and search for the jump Z velocity parameter this one I'm going to say it to something like 500 and now if I launch the game you can see that it's much better now okay so now before moving on to implementing the ability to move around first let's focus on looking around so this is the action that we are looking for so what we are going to do here is rotate the selfie stick based on the player inputs so that the camera can align The View with the direction the player wants to look in so when we are going to use our right thumbstick this will move the selfie stick to align with what the player wants to see so to achieve this first I'm going to add a bit of code to the look around even I'm going to select this delete and then I'm going to drag a wire from the trigger pin type add controller and select add controller your input then I'm going to drag a wire from this new node and type add controller pitch input then I'm going to right click on the action value right here select split struct pin to extract the X and the Y separately then I'm going to plug the X in the add controller yo input and the y in the add controller pitch input here I'm going to double click to other route node and there you go so what this code does is updating the control rotation which is the controller rotation which specifies the direction the character should be facing whenever we move the mouse or tilt the right thumbstick to do so this code uses two nodes one for updating the Yo which makes the camera look left or right based on horizontal movement of the input and one for updating the pitch which makes it look up and down based on vertical input now if I launch the game you will see that the character turns with the camera which is something that we obviously don't want to happen to solve this we need to decouple the character's rotation from the controller's rotation by going back to the BP hero then clicking on plus defaults and typing controller in the search bar here I'm going to uncheck the use controller rotation new parameter now if I launch the game you will see that the character is effectively not rotating anymore that's great but now that we've decoupled the character's rotation from the controller's rotation we are going to link the ladder to the selfie sticks Rotation by selecting the selfie stick in the components Tab and check in here the use bone control rotation parameter this one use bone control rotation I'm going to check this parameter so that it can rotate based on the player's input so here if I launch the game you will see that the look around works correctly since the selfie stick follows the movements of my mouse okay so great so now before moving on to the next section we are going to add the possibility to invert the camera X and Y axis to achieve this first I'm going to create two new variables of type Boolean by going here in the variables I'm going to click on the plus sign and I'm going to rename this new Boolean to invert camera X and then I'm going to click again on the plus sign and type invert camera y then I'm going to add a piece of code and explain it to you how it works after so here I'm going to press alt on my keyboard and click here here I'm going to put it here I'm going to get an invert camera X click on get then I'm going to drag away from here type select float in the select float a parameter I'm going to put -1 the B I'm going to put one and then I'm going to drag a wire from the action value X press multiply on my keyboard and select the operators multiply here I'm going to plug this right here and this right here and now I'm going to select this press Ctrl D on my keyboard to duplicate it I'm going to plug this right here right here float here and then I'm going to double click to make some space right here and then I'm going to get the invert camera Y and drag it here to replace it right here so this piece of code is easy to understand since all it does is converting my booleans to -1 if they are true and one otherwise which will have the effect on we are inverting the axis whenever we set any of this variable to true so here for example if you try to select the invert camera Y and set it to True by checking this box right here if you launch the game you will see that the camera rotation direction is successfully inverted so since I prefer my camera to not be inverted I'm going to uncheck this option and we can move on to the next part of this tutorial okay so now let's focus on creating our final gameplay mechanic which will allow us to work around here just like with the jump we implemented earlier the character class has built-in functionalities for making our character work around and before moving on to the implementation if you want to have a look at how it is set up you can select the character movement component here in the components Tab and go to the working category in the details tab on the right side of the screen so here you have the working category and you will find all the related parameters such as the speed which is set to 600 centimeters per second ground friction that you can see right here breaking deceleration here and much more now to make the character work we are going to implement it by connecting two add movement input nodes to the input action move around okay so here we have the input action move around I'm going to select this delete and then I'm going to drag over here from the triggered pin type add movement input and then I'm going to duplicate this press Ctrl d and plug this right here so the first add movement input will be responsible for moving the character left and right and the second one will be responsible for making the character move forward and backward so first we are going to focus on the left and right movement so this one here what we want to do is make the character move in relation to the camera rotation so when I tilt the left stick right I expect the character to move towards the right side of the screen to do so I'm going to get the control Rotation by right clicking here typing get control rotation which represents the direction the character is facing then from this control rotation I'm going to get its right Vector I'm going to drag a wire type right vector and select the get right Vector function this get right Vector function gives the direction to the right then I'm going to plug this in the word direction parameter of my first add movement input that specifies the direction towards which remote our character to move now if I launch the game you can see that the character is going to the right whenever I press one of the move around keys it's great and all but if I want to make the character move accordingly to the horizontal inclination of my thumbstick this is where the scale value parameter so this one comes into play before I explain to you how it works I'm going to right click on the action value right here and select split strict pin to extract the X and Y values separately then I'm going to plug the x value to the scale value and here I'm going to add a reroute node by double clicking and placing it right here okay so here when working with the add movement input node the scale value parameter is used for two things first it's multiplied by the word direction parameter this one which causes the character to work in the desired Direction when the scale value is positive and in the opposite direction when the scale value is negative second it's also multiplied by the max working speed parameter of the character movement so this is the max working speed that was set to 600 centimeters per second so when multiplying this value by the max working speed parameter this has the effect of making the working speed of the character vary based on the angle of the thumbstick now if I launch the character you can see that the character moves left and right based on my inputs so now let's move on to setting up the forward and backward movements first I'm going to connect the Y value of the input action to the scale value of my second add movement input node and then since we want the character to move along the forward direction of the camera view we are going to get the controller rotation okay control Rotation by right clicking here typing get control rotation and selecting the control rotation this one then I'm going to get this forward Vector to get the direction for one here I'm going to plug this in the word Direction so that whenever I tilt the stick up and down we will go forward or backward based on what the player is currently looking at so now if I launch the game you can see that the character is correctly moving around along the desired Direction but it seems to work slower when the camera is viewing from A View angle that is not parallel to the ground so here if I go to the top of the character and press my up and down input you can see that the character does not move anymore to prevent this from happening we are going to remove the pitch component of the control rotation to simulate the camera being aligned with the ground to do so I'm going to press alt on my keyboard and click here then I'm going to right click here select split strict pin and then I'm going to right click here select split struct pin and then I'm going to plug everything but the pitch Rotation by doing this you are simulating the fact that the camera is always aligned with the ground now if I compile save and if I launch the game we can see that everything is working as expected and that the working speed of our character doesn't vary based on the camera view angle okay so now before moving on to the next section let's make it so the character constantly face the direction in which he's moving by clicking on the character movement right here here in the search bar I'm going to type Orient and then I'm going to check the Orient rotation to movement parameter now if I launch the game it works correctly but I think that it will be better if the character rotation rotation was faster to do so I'm going to select the character movement again then I'm going to type rotation rate in the search bar and here I'm going to increase the Z value of the rotation rate to something like 700 to make the character turn faster so here if I know the game there you go the character turns faster and we have our blueprint of our character which is done now we can start animating it so that it would look like a scarecrow sliding around in the level okay so now we are going to create our first animation blueprint which will help us handle our character's animation but before creating it since an animation blueprint needs to be bound to a skeleton so avoid any confusion let's start by finding the skeleton that is assigned to our skeletal mesh to do so I'm going to go to my BP hero then I'm going to select the mesh component which is the visual representation of our character and then on the right side of the screen right here I'm going to double click on the thumbnail so here this will open the skeletal mesh editor in which you can see how our character is made and here you can go on the left side in the details panel as set details and you can search for skeleton this is the skeleton I said you can click on the browse button right here to go to the skeleton asset okay so my skeleton is the SK mannequin skeleton so now I'm going to create my animation blueprint I'm going to press Ctrl space I'm going to go to the content right click here I'm going to select animation then animation blueprint so here unreal will ask me what skeleton I want to assign so here you will assign the skeleton that you found for your own character and here I'm going to select the SK mannequin skeleton I'm going to press create and then I'm going to rename it to ABP for animation blueprint underscore hero okay so now before opening this new asset let's assign it to our character blueprint so that we will be able to play animations on our skeletal mesh so here I'm going to go to my BP hero then I'm going to select the mesh component and here on the right side of the screen you have the animation category this one and you have animation which is set to use animation blueprint if it's not set to use animation blueprint you can click and select use animation blueprint and then I'm going to assign my new animation blueprint by selecting an in class clicking right here and selecting ABP hero now I'm going to compile save and we can close our blueprint I can also close my skeletal mesh editor and here I'm going to press Ctrl space and double click on my ABP hero to open it so here the role of an animation blueprint is simple it chooses which animation to play on our character based on what the player is currently doing I won't go into a detailed presentation of the anatomy of an animation blueprint but just so you know it's composed of two main parts the first one is the event graph and this is used for fetching the characters properties that are relevant to choosing the correct animation to play such as if it's in air or if it's working for example so this will fetch the parameters in the corresponding blueprint so in our case the BP hero this will fetch the information that it needs to play the correct animation of our character and then the second part of an animation blueprint is called the anime graph that you can see right here you can also open it by clicking here on any graph or even graph so the anim graph plays the corresponding animation based on these fetched properties as well as the current state of the character so this will be the place where we'll say that we should play the jump animation when the character is jumping or the working animation when the character is working and speaking of animations if you want to see how they look and how they work you can click here on the green button on the top right corner of the UI this will open the animation editor so here you can see a list of animations I'm going to put myself in the middle of the screen right here here on the right side of the screen you can see the list of animations that our character have as for me you have the full animation the idle animation for where the character stays in place the jump animation and the Run animation and now if you click on the browse button right here you can see that these are actual assets that can be recognized thanks to the green line below the thumbnail okay so now we are going to start implementing our animation blueprint by first fetching the character's properties that will be relevant to choosing the correct animation to play and to do so first we need to get a reference to the pawn to which this animation blueprint is bound in our case the pp hero and to do so here I'm in the event graph you can go in the oven graph by double clicking right here and then I'm going to zoom on these two nodes and I'm going to drag a wire from the try get bone owner and type BP underscore hero after this I'm going to plug the blueprint update animation to the guest 2b0 and what I've done here is that I get the pawn owner which is the point which this animation blueprint is bound and then I tell only Engine 5 that this phone is of class BP underscore hero here just so you know doing this in the event update animation is not the most optimized way because this event is called every frame there are better ways of doing this of course but since we are mostly here to understand how this all works we'll be okay with that so now that we have a reference to our character we can start to get the properties that are relevant to our needs and season 2 character will only be able to move around and jump we only need to know the speed at which it's currently moving as well as if it's in air or not first let's start by getting the character's current speed to do so I'm going to get the velocity of the character from the character movement here with Dragon Wire and type get character movement this get character movement and then drag away from this end tape you can get velocity this one okay so doing this the velocity gives the direction and the speed at which the character is currently moving then I'm going to get the vector length x y of the Velocity to extract the speed component of the Velocity from which we remove the speed along the Z axis to only keep the ground speed of the character okay so here we get the length and then once it's done I'm going to right click on this and select promote to variable to store the result in a new variable that I'm going to rename to this way I will be able to access this value later when I implement the logic for playing the correct animation okay so here's a quick recap here I get the BP hero from the BP hero I get the corrective movement from the character movement I get the velocity of the character which gives the direction as well as the speed and then I extract the speed of the character on the ground and store this value into a variable so now let's move on to checking if the character is in air or not it's pretty easy to do since all we have to do is drag a wire from the character movement right here and type is falling then I'm going to right click select promote to variable to store this into a new variable and then I'm going to rename this new variable to in air so thanks to this piece of code the in a variable will be true if the character is in air and false otherwise okay so now that we have all the info we need for the players animation we are going to go to the animation graph to implement the animation logic so the animation graph is a special type of graph that is used to choose which animation to play based on the interpretation of what the player is currently doing when working with the animation graph it's counterintuitive I know but we don't talk about animations but poses and the output pose node you see here is where we are going to fit the final animation our logic which will choose based on what the player is doing okay so first let's start by making it play an ideal animation no matter what happens so here I'm going to go on the asset browser on the right side of the UI I'm going to put myself on the left side and here you have the asset browser you can open it by going to window and selecting a set browser here you will see all the animation that are assigned to our character I'm going to get the ideal animation for when the player is in place and here I'm going to drag this in the graph then I'm going to plug this in the result and press compile and you will see that our character will start moving so now we have our character that plays an ideal animation I'm going to remove the visualization of the skeleton by going to character bones and selecting selected only so now we can see our character move and if I launch the game you will see that our character plays the idle animation no matter what I do so now we are going to add the possibility to change from the idle animation to the run one if the player is moving around unfortunately contrary to the blueprints we usually use Branch nodes are not available in the animation graph instead we are going to use what's called a state machine so here I'm going to select this and delete and then I'm going to right click type State machine and select state machine here I'm going to select this press f2 on my keyboard to rename it and type main State machine here I'm going to plug this state machine right here and here if I press compile you will see that the character is not moving anymore and we have a warning right here so here I'm going to double click on it to open our state machine and for those of you who don't know a state machine is like a set of instructions of how a character should animate in different situations for example in our case if the character is staying in place the state machine will play the either animation of our character but if the character starts working the state machine will make the character transition from the idle animation to the working animation to adapt the animation to where the player is currently doing so now let's make our animation blueprint work as it was working earlier by setting our state machine so that it always plays the idle animation to do so I'm going to right click select add state to create a new state I'm going to rename this new state to idle and then I'm going to connect it to the entry by dragging a wire from here to here so that whenever we enter the state machine we go in the either state by default so here before launching the game to see if it works we need to assign an animation to play when we are in the either side to do so I'm going to double click right here and here I'm going to get my idle animation drag it here and plug this in the output animation pose so now if I compile save and launch the game you can see that the animation works just like before okay so now that our either state is working correctly let's move on to handling the Run animation so here to grab the hierarchy you can either double click anywhere in the graph or click on the main State machine right here on the breadcrumb at the top so to automatically create a new state to the state machine we can grab the Run animation right here and drag it in the graph now we created a new state I'm going to rename this node state to run and here if you double click on the state you can see that the Run animation was automatically assigned to the state so I'm going to double click to go up the hierarchy and then to be able to transition from the idle state to the Run State we need to drag a wire from the idle state to the Run state note that here the connection are arrows which means that the transition goes exclusively from the idle to the run so the small batch you can see above the arrow is named a transition Rule and holds the condition that must be met in order for the transition through the Run State occur here we want the transition to the Run state to happen whenever the player starts moving around to achieve such a thing I'm going to double click on the transition Rule and create a transition that tests if the speed of the character is greater than zero to do so I'm going to drag my speed variable right here drag it in the graph select get speed and then I'm going to drag a wire and type Raider I'm going to get the Creator here I'm going to plug this here and this way if the speed is greater than zero we can enter the transition which will make the character grow from the idle to the Run state so now if I launch the game you can see that we have two issues with the animation first when I start walking around the character has successfully placed the animation but if I stop it doesn't transition back to the idle animation the second issue that you saw right here is that when the character finishes playing his working animation it doesn't Loop so now to solve this second issue I'm going to go to the Run state by double clicking on the Run State here and here I'm going to select the Run animation on the right side of the screen I'm going to search for Loop animation which is available right here I'm going to check this parameter and then I'm going to click on the button right here and select expose as pin that way we will see right here that the loop animation was set to true and we won't forget that the looping is happening for this run animation now if I launch the game we can see that the animation does loop but if I stop running the animation doesn't go back to the idle to solve this issue we are going to create a transition that goes from the Run state to the either state by dragging a wire from the run to the idle here you will see that we have another transition rule that appears and to set up this transition rule I'm going to double click on it and all we want to do is go back to the idle state so you can see here that we are in the rule that goes from the run to the ideal State and if I want to go back to the either side all I have to test is try to see if the speed the speed variable is equal to zero so here's pin I'm going to drag a wire and type less equal this one less equal zero so here if the speed is equal to zero our character will go back to the idle state so here compile save and if I launch the game you can see that you've successfully created your first animation blueprint State machine okay so now that we can handle animations when our character is on ground let's move on to setting up the jump which is composed of two distinct animations the start of the jump which is Then followed by the following Loop animation that will keep on playing as long as the player is in air so here if I go to the jump I'm going to double click right here to open this animation so this is the jump start and as soon as the jump start finishes playing we want to play the for Loop for as long as the player remains in air so here I'm going to go back to my animation blueprint and first let's create an animation state for when the jump starts by dragging the jump animation into the graph I'm going to rename it to jump start and here we want to trigger a jump whenever we are in the either state or in the Run state so we are going to drag and transition from the idle to the jumpstart and another one from the run to the JumpStart for the transition rules we want these transitions to occur occur as soon as the player is in air to do so we just need to double click on one of the transition and here I'm going to add the in-air Boolean this one the in-air variable we created earlier I'm going to select it and drag it in the transition that way it transitions from the idle to the jumpstart will occur as soon as the in a parameter is set to true then I'm going to go back to my state machine and then I'm going to double click on the other transition the one that goes from the run to the jumpstart and plug the in-air variable in here as well so that way when in air is set to true we will go from the run to the jumpstart now if I launch the game you can see that it does work but now we need to make it so we transition to the following Loop animation as soon as the jump start animation finishes to do so I'm going to create a jump Loop state by dragging my full loop animation in the graph right here then I'm going to rename it to jump Loop then since it's an animation that needs to Loop for as long as the character is in air I'm going to double click on the jump Loop State select the animation here on the right side of the screen I'm going to check the loop animation parameter and expose it as pin so that I won't forget that it is looping so here I'm going to go back to the state machine and the only way to transition to this new state is from the jumpstart animation so we are going to drag the transition cable from the jumpstart to the jump rope then as for the transition rule we'll make it so the state machine can transition to this new state the jump loop as soon as the jump start is finished to do so we don't need to go in the transition rule to code something since all we need to do is select the transition Rule and check on the right side of the screen this one automatic rule based on sequence per year instead okay so here I'm going to check it and this way I'm going to make it so Unreal Engine will automatically transition to the loop as soon as the start animation finishes playing so now if I launch the game and jump you can see that it does work but now we need to transition back to the run or either State as soon as the character touches the ground to do so first I'm going to drag and transition from the jump Loop stay to the run one and then I'm going to drag a transition from the jump Loop to the idle state okay here I'm going to make some space so that it can be more readable and then I'm going to set up the transition from the jump Loop to the idle by going into the transition rule this one and then I'm going to make it so the character will go back to the idle only if it's not in air and if it's not moving around so here I'm going to drag and in a variable in a graph get in air and speed variable in graph 2 get speed and here we need to code a small piece of code I'm going to drag not Boolean and here the speed I'm going to drag a less equal and here I'm going to drag away from the nut and type end I'm going to select end Boolean I'm going to plug this right here and this right there so here what I'm doing is that I'm trying to check if the character is not in air and the second thing that we are checking is if the character speed is equal to zero so if it's not moving and the end means we check if the character is not in air and if its speed is equal to zero so now that we can check if it's not in air and if it's not moving around I'm going to go up the hierarchy by double clicking in the graph and then I'm going to go in the transition rule for going from the jump Loop State this one to the Run here I'm going to create a code that will make the character go back to the Run state if and only if it's not in air and if it's moving around so I'm going to drag a speed variable get and in a variable to get I'm going to drag a not Boolean and here instead of getting the less equal I'm going to drag a greater greater than zero and Boolean so here if the character is not in air and if its speed is greater than zero we should go to the Run state so now since it's also possible to land while we are in the jumpstart animation we are going to drag a transition from the jumpstart to the run and from the jumpstart to the idle so in here I'm going to drag this and here I'm going to drag this one too then I'm going to go to the transition rule from the jumpstart to the idle and then I'm going to cut something but since it's the same that we've created earlier I'm going to go back to the hierarchy and select the transition that goes from the jump Loop to the idle double click on this I'm going to select the not in air and speed less equals zero I'm going to press Ctrl C on my keyboard I'm going to go back to my transition from the jump start to the idle this one and here I'm going to paste this code here if the character lands while being in the jumpstart animation we are going to go to the idle state then I'm going to go to the transition that goes from the jump Loop to the run so this one jump Loop to run I'm going to go inside select this press Ctrl C on my keyboard to copy this and then I'm going to go back to my jumpstart to run transition this one jump start to run and here I'm going to paste this because this is the same we go from the jumpstart to run if the character lands and if its speed is greater than zero so now I'm going to compile save I'm going to go back to my main State machine right here and if I launch the game we can consider that our character is done because the character is now running jumping and playing the following animation correctly however we're going to take the code a step further by optimizing it a bit okay so here our state machine has a problem because it has transition rules that are repeated multiple times and are the same for different states which makes it difficult to maintain for example if we take the jump Loop State and the jump start States they both have the same two transition rules for going to the run or the idle State as you can see this one and this one are the same and this one and that one are the same two if someday we decide to change the way we test if the player has landed for example we would need to remember to change it for all the transition rules that have the same condition this is a simple State machine of course but if we are working with more complex State machines it can be a bit of a mess so this is a process that can be cumbersome and to prevent this from happening we are going to use State aliases which will help us unclutter our state machine so here a state Alias doesn't have any animation assigned to it and can be seen as a pre-configured set of transitions that you can then assign to a normal State and to better understand how it works first we are going to create our first state Alias by right clicking in a graph selecting add State Alias and renaming it to to ground now let's configure the state Alias as if it was representing the player being in air and landing on the ground to do so I'm going to drag a transition cable from the Alias to the idle here and another one from the ideas to the Run State then just like with the jump Loop of the jump start I'm going to set up the transition to the either state by going in the corresponding transition right here and then I'm going to make the character go back to the idle only if it's not in air and if it's not moving on ground to do so I'm going to go even faster by selecting the transition from the jump Loop to the idle and here I'm going to select this press Ctrl C on my keyboard and go to my two ground transition to ground to idle and paste it right here so here I'm going to go from the two ground Alias to the idle state if the player landed so if it's not in air and if it's not moving around so after that I'm going to go up the hierarchy and then I'm going to double click on the to ground to to run state by double clicking here I didn't choose the correct the good name so here I'm going to make it so we go from the to ground to the Run state if the player has landed and if he is moving around so here I'm going to go to my main state I'm going to go in the jump Loop to run transition because it will be the same and here I'm going to select the condition copy this go back to my transition that goes from the two ground Alias to the Run State here I'm going to double click and paste it right here so now I can compile save and now that our set of transitions has been configured we are going to assign this preset to the jumpstart and do jump Loop states by selecting the Alias and here in the details panel you can assign this new preset to the jumpstart by checking this and the jump Loop by checking this and finally since the transition preset represented by the two ground state Alias has been assigned to the jumpstart and the jump Loop we can remove all connections that go from these states to the run and either States so here we have the jump Loop I'm going to select the transition to the Run delete it select the transition to the idle delete it and then I'm going to select the jump start and delete the transition that goes to the idle state and delete the other one that goes to the Run state so here if I compile press save and launch the game you can see that everything is still working correctly even if we have less Connections in our state machine so now let's handle the two transitions that go from the run in either State this one the run and either state to the jumpstart here both of these transitions have the same rule since they both occur whenever the in air Boolean is set to true to simplify this I'm going to create a transition preset for the ground related states that need to go to the related ones by right clicking here select add State Alias then I'm going to rename it to 2 here and then I'm going to connect this to the JumpStart then once it's connected I'm going to open the transition rule of the state ALS and then I'm going to plug the in-air variable to the condition that way we are going to go from the two air to the jump start State once the in air is set to true and finally since it's going to be an alias for the run in either state I'm going to select the Alias and then I'm going to check the run and idle state so that it will be set to the run and idle and finally since we've done this we can remove the connections that go from the run to the jumpstart selecting this delete and selecting the idle and deleted two and there you go now we have a graph that is much more clean and readable and here if I launch the game you can see that it still works as expected but that's not all now we are going to take the simplification a step further by creating a second state machine okay so now if we have a look at our transition rules we still have duplicate conditions such as in the two two ground transition where we check if the player is not in air so not in air and not in air that you can see right here or in the two transitions that enter the Run State this one and this one where we check if the speed is greater than zero so to simplify this we are going to use a second state machine for handling when the player is on ground that way when the player lands on the ground instead of making our two ground Alias choose whether we should go to the idle order instead we are going to transition to the second state machine that will be responsible for choosing if we should play the run or the idle animation based on the player's movements so here the first thing I'm going to do is create a state machine just for when the player is on the ground I'm going to go to my anion graph right here then I'm going to right click type State machine and here I'm going to select state machine then I'm going to select this state machine rename it to ground Locomotion and then I'm going to my main State machine select the idle and run State press Ctrl C on my keyboard to copy this and then I'm going to go back to my new round Locomotion State machine and press Ctrl V to paste these two right here oh so it didn't take the transition rules so I'm going back to my main State machine select everything press Ctrl C here Ctrl V and there you go so here I'm going to connect them like this so that way when we go to the ground Locomotion we have only two states one idle and one Rand that changes based on the value of the speed parameter so now if I want to use this new state machine in the main one I need to store the result in a cache which can be seen as a variable in which we can store an animation so here I'm going to drag a wire type cache and select new saved cache pose here I'm going to press f2 on my keyboard and rename it to ground Locomotion cache so this can be seen as a variable in which we store the result of the ground that way we can use this variable later in this tutorial to plug the the result of this state machine in another state machine so now that everything is set up I'm going to go back to my main State Machine by double clicking right here here I'm going to delete the idle and the Run State and here I'm going to right click select add State and type ground locomotion then I'm going to plug this right here and here I'm going to make a transition from the two ground Alias to this new state then since I want to enter the ground Locomotion State machine whenever the player lands on the ground I'm going to double click on the transition Rule and here I'm going to drag an in a variable right here get in here and drag a wire type not Boolean and then I'm going to connect this that way we will go from the to ground to ground Locomotion whenever the in air parameter is false okay so I'm going back here and then since the run and idle state do not exist anymore I'm going to select the two air Alias and apply it to the ground Locomotion instead by checking this right here and finally I'm going to open the ground Locomotion State and make a call to my cache I'm going to right click type ground Locomotion and I'm going to select the use cached pose ground so here whenever the ground Locomotion state will be active the logic of our second state machine will play the corresponding animation based on if the player is currently moving or not so here if I press compile save and launch the game you can see that our character works correctly congratulations you've created your first animation blueprint your first enhanced inputs and your first playable character I really hope that this tutorial helped you better understand how third person characters are made in on range in 5 and if you want to learn more cool stuff about Android engine you can click on this video and I'll see you over there let's move on mapping and let's move on move on move on input actions in Productions character by state based camera X and Y axis axes axis axes
Info
Channel: Evans Bohl
Views: 22,647
Rating: undefined out of 5
Keywords: unreal engine 5, ue5, third person tutorial, unreal engine 5 animated character, 3rd person animation tutorial, create a playable character in ue5, unreal engine, enhanced input system, input action, input mapping context, how to animation blueprints, animation blueprint, state machine, animation blueprint alias, character blueprint, blueprint tutorial
Id: Ymsabf0ZQuE
Channel Id: undefined
Length: 70min 16sec (4216 seconds)
Published: Tue Jan 17 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.