UE5 - Basic Locomotion: Turn In Place (REPLICATED)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
oh what's up guys so today we're going to continue our Locomotion system and we're going to implement the turn in place okay so let's begin um first things we need is to import the animations so let's go to characters mannequins animations manyu unarmed and create a new folder called turn open it up now get the animations that are in the description or from the Lara templates the four animations drag them in select the skeleton import all okay so now right click asset actions bulk edit go to root motion enable in force root lock file save all close this now we need to create a montage for each animation so right click create animation Montage so now uh we have all the our montages you can uh save this and we can start to create functionality that will play this montages so let's go to content third person blueprints character and let's go to our replication graph and right here we're going to create some events that will allow us to play those montages so here say add custom event this is going to be called play okay this is going to run as a multicast event which means it will be broadcasted to all the clients and right now we're going to create a new variable called Turning to check if we are turning or not and from here we're going to say branch and we are going to connect the turning right here like this so if we are not turning then we're going to get this and say set and set the turning to true so we're going to start turning so after that you can say play Montage this one now you can grab the skeletal mesh and connect right here and the Montage will come from the event and the play rates will also come from the event like this uh now after this we can say delay and the duration of this delay will also come from the event this way we can call this event and tell it what Montage to play so after that we can set the turning to false once this is completed and once the animation is completed so that's it um we have the event to play the animation now we need to create um separate events to play the specific animation that we want so right here we're going to say add custom event we're going to say turn right 90 you can copy this one and call it turn left 90 you can copy this two and say turn right 180 and turn left 180 okay now you need to set all these events to run on the server like this okay um now you can give them a little bit of space and all these events will call the event that we created before so from here you can say Play Turn you can can uh copy this to all the events like this and connect everything okay so the first animation the turn right 90 we are going to play the Montage which will be the turn right 90 Montage the play rate will be 1.5 and the duration will be 0.5 okay now the turn left which will will be turn left 90 the duration sorry the play rate will be 1.5 and the duration will be 0.5 okay now this one's uh the animation will be the turn right 180 the play rate will be 1.7 and the duration will be 0 uh six um because this animation is a little bit longer so makes sense that we increase a little bit now uh the turn left we will set turn left 180 and this one will have uh 1.7 on the play rates and 0.6 for the duration that's it now we have uh all the events to go in each Direction now what we also need uh so we can um call this turn in place and now uh we need to create um another event which will allow us to clear the animations when we need that so for example if you are turning and you try to move forward the character will not move uh because it's playing a root motion animation which means the motion of the character will be based on the animation and not on the movement input okay so right here we're going to create create another event add custom event and this will be called clear motion this will be uh running as a multicast and um from here we're going to say is playing animation root motion so Branch if we are then we can get current montage and then we can say stop Montage okay if this is true then we stop the Montage um we can comment this and say clear Roots motion like this uh we separate this because you might uh use this with other things so makes sense that it is separated now on the turnning place we're going to expand a little bit and we're going to create another custom event called clear turn in place in place okay and this will be running on the server now uh here we will take an input which will be the force and it will be a float so this will basically be um the value from our movement axis which will tell us uh if we are trying to move or not so so from here we're going to say not equal to zero so uh if this basically it's not zero then we can say here brench and we can say clear motion okay now can organize this and that's it um now what we need is to create a function that will check uh which angle we are crossing and will trigger all these animations so let's create a new function here called uh turn in place now we need to check a few things so we can get a branch like this and from here you're going to say and now from here you're going to say not Boolean and you're going to copy this like that we're going to add a pin and connect this like this so that's it now the first thing we need to verify is if our character is not falling so we're going to grab the character movement and say is falling and connect right here so if we're not falling then we can proceed now the second thing we are going to check is if our character uh has no speed so he's not moving so we're going to grab the character movement we're going to say get velocity which is down here and from here we're going to say Vector length XY which will basically give us the value of our current speed and from here we going to say uh greater than zero so if our speed is not like this greater than zero then uh we can proceed okay now the last thing we're going to check is if we're not crouching like this okay now um the next thing we're going to do is another check so you can copy this here and we're going to check if we are crossing the 45° angle which means that we have animations to play right so uh here we're going to say get Act rotation and here gets base aim rotation from here going to say Delta and connect these two now you're going to split the structure here and the yaw value will be basically the angle that we are trying to move to so here we're going to say multiply and we're going to multiply by minus one which means that we are Inver in this value now uh if this is greater than 45 or less than minus 45 so or less okay then we can proceed so now you can move this here and that's it so the next thing we're going to check is which angle uh that we are crossing at and which animation we should play so you can grab this Branch call it right here and copy it again and again and again okay now just connect the false to the following like this so which means that we're going to check one and then if it's not so we're going to continue to check the other and the other and the other so now we can connect the true right here and we can grab these great or less things paste them here now this one is going to go here and connect all these things now you can copy these two and paste them here and connect as well so now um we can grab the yaw value from here and connect to which uh thing right there okay like this um sorry like uh this like this okay now the first angle we're going to check is the 135 2 minus 135 okay so and this ones are already correct from 45 to minus 45 so if we are crossing this angle then from here we're going to say turn right 180 okay so we're going to call the animation now from here we're going to say turn left 180 this one will be turn right uh 90 and this one will be turn left 90 okay so can organize this if you want and that's basically it so we check if we not uh doing any of this stuff then we check if we are crossing the 45° angle and if we are we check which animation we should play okay uh so that's basically it now we can go to the event graph and on the camera input on the mouse right here you can expand this and call the turn in place like this okay now uh what we can also do do is on the GamePad we can also do the same thing so we can move this here a little bit drag this here copy the turnning place and place it right here okay so this way it will work on both now um the other thing we need to do is clear the motion when we are turning and the player is trying to move so on the movement input we're going to say clear turn turn in place okay now we're going to connect this here and this over here and now the force will be the axis value okay now the same thing right here so you can connect this like that and the force will be the axis value so uh if the axis value is different than zero then we clear uh the root motion animation uh now the the other things that we need to do is also for example when we jump we also want to clear the root motion animation so that we can jump and when we Crouch we also want to do that so here on the jump we can just copy this and when we jump we can call the function and set this Force to one which means that uh we're kind of simulating the AIS value so that we can uh stop the animations now you can copy this one and and let's go to the replication graph to the Crouch like this and you can move this um right here you can expand this a little bit like that and you can paste here the clear turn in place connect them both to the node and the force don't forget it has to be one okay so that's basically it um we should now be able to use it if you want to see this better you can enable the bubbles right here and this way you can navigate on the graph knowing uh where to go so basically this way you can see where everything is so we should be able um to use these animations now so let's test it out so hit play and if I go to the right I turn to the right and to the left and if for example I jump and turn it will play the 180 animation okay so as you can see everything is working we can use the turn in place um I can also test this on the server if you want so here I'm going to select three players not two because it's also important to see if the other clients uh see the animation on the other clients okay so I'm going to use this one and as you can see when I turn all the screens see me turning okay so that's basically it now we can test that uh with our other client right here and if we go forwards you can see when I rotate they also see it so that's it um I hope you liked it I hope you learned something with it and don't forget to subscribe
Info
Channel: Native Coder
Views: 13,636
Rating: undefined out of 5
Keywords: ue5, unreal engine, ue4, metahuman, metahumans, meta-human, integration, fast, quick, new, method, new method, videogames, development, advanced locomotion system, marketplace, locomotion, advanced locomotion, tutorial, easy, replace character, retarget, animations, basic, 8-way movement, movement, lyra, strafe, replicated, beginner, turn in place, turn, rotate, replication, multiplayer
Id: 6oBvmI4RkZk
Channel Id: undefined
Length: 16min 53sec (1013 seconds)
Published: Fri Sep 29 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.