Transcript

Use with ChatGPT / Claude Auto-scroll A

1. Episode Intro and Slow-Motion Debug Key

Introduction to the episode's goal of fixing foot sliding with stride warping, plus setting up a time dilation debug key to slow gameplay for inspection.

0:00 - 0:57
Namaskaram, everyone.Welcome back to the ninth episode of our master Unreal series.So, in the last episode, we created a function to update the physics parameters in the character movement component that allowed us to tweak the values of speed, acceleration, friction, and what's not when you are walking or running.Now, in this episode, we are going to address the issue of foot sliding.I'm trying to move, and you can see my foot is sliding.Now, the reason it is sliding is because the speed that we configured in the movement component is not matching with the animation speed.This issue can also happen when you are having uneven terrain.So, in those cases, the distance that your body is traveling and distance your animation is traveling might differ.And to fix that, we are going to use the stride warping.It dynamically adjust the distance to match your character speed.
So, it's what keeps your character feeds firmly on the ground without sliding or looking out of sync.So, when you are moving, your foot doesn't slide.Instead, it plays where it exactly needs to be based on the speed or the terrain on which you are walking on.So, before we start, uh we want to slow the time when we are, you know, debugging.So, for that, just go to your character blueprint, and inside the event graph, right click and search for alt or any key that you want to use as a debugging key.So, I'll do this left alt, and when it is pressed, then I will say set global time dilation to 0.2.And when it is released, set it back to one.Okay.Now, if you hit compile and play, now if you hold alt, you'll see the time slows down.

2. Enabling Stride Warping and Calculating Displacement

Enabling the animation warping plugin and adding the stride warping node, then building a thread-safe function that computes frame-to-frame displacement using actor locations and vector length XY.

Okay, so now let's start with the stride warping part.So to implement this solution, you have to enable the animation warping plugin so that it gives you the stride warping node.So if you're not following the series, I highly recommend you check out the first four episodes to see how we set up the locomotion system.So once the locomotion part is implemented, you can go to your base and in the base, you go to your animation graph under this locomotion state machine and the walk cycle.So this is what we implemented last time.Now we are going to add the stride warping node here.So let's add it.So there are two ways to set up this stride warping node just like this orientation warping.Either you calculate all these three values manually or you leave it to Unreal Engine by setting it to graph.
Once you do that, you just need to provide the alpha and the locomotion speed.So let's first calculate the locomotion speed and update it every frame so that stride warping is using the correct data every frame.So for this, we are going to create a function that is going to update the location data.Okay?And this function is thread safe.Like I said before, the stride warping node adjust your distance dynamically and to do that, we need the speed and the time.When I say speed, I mean the displacement speed.All right?So from one frame to the second frame, how much displacement you have covered, we want to know that speed.So for that, we are going to create another variable that is going to store the displacement speed.And we are going to change its type to float.But to calculate the displacement speed, you need the displacement and time.
So for this, I'm going to create another variable, displacement since last update.So this displacement gets updated every frame.And that is what we are going to use to calculate the speed.So you connect this to this, use the property access node.And like I explained in the second episode, the Unreal hierarchy system to get location, rotation, and scale, you will use the get owning actor, and this will tell you the actor's location.So this location that you're fetching, it is the location of actor at this particular frame.But we have to subtract it from the previous frame so that we can get the change.So to get the previous one, you have to create a variable that stores the location.So for this, we are going to say character location.And location is a vector quantity, so I'll change its type to vector.Now, assuming that this character location have the previous frame's location, and this property access node is giving the current location.
So we can subtract this.So search for subtract.Once they are connected, now you have the difference, but we want the displacement only in the XY plane.Our character is not moving in the Z direction or in the sky.So in the XY plane, if you want to get, you will do vector length XY.So this will give us the magnitude of that displacement, because displacement is a vector quantity, and to use it in mathematical calculations, we need the magnitude of that.So that's why we use this vector length XY.Now, once this is done, we would like to update this character location with this new current location that we are receiving in this frame.So let's bring out our node.Connect this to this.And remember, this one is the location.

3. Computing Displacement Speed with Delta Time

Dividing displacement by delta time to get displacement speed, handling the first-update edge case, and wiring the function into the thread-safe blueprint with locomotion data.

Now, once you have the displacement, you can calculate the speed.So, I will bring this displacement speed here and connect this to this.Now, you can do the division of displacement upon time as per physics.So, I'll say safe divide just to avoid the errors that can happen if the B becomes zero.So, I'll get this displacement.Now, we need the time.And the time is not what we see in the clock, but it is the time elapsed between the last frame and the current frame.So, every player has their own system, own configuration.Some are Some players might play our game at 30 FPS, some might play at 60 FPS.So, we have to apply this time based on their specs, okay?So, we need to get that time.So, now to get this time, we need to take help of the blueprint thread safe.
But before this, we want to include an input parameter that would tell us the delta time.And this would be of type float.Now, if we compile first and go to our blueprint thread safe we can add our update location data function here.Connect this to this, this to this, and this delta time will be plugged into this one.Compile now and go to our function, and now we can call the get delta time variable, and we can plug into this.But we have one more situation, that is the displacement speed is calculated when you have displacement.And to have displacement, you need to have the location of the actor from previous frame, which is not possible when this function is executed first time because in that case, you do not have any previous location.So, for that case, we are going to create a variable and call it is first update.
If it is so, also let's first compile and hit this to true, and then bring a branch node.Bring this variable, connect this to this.Now, if this is a first update, then we want to set displacement speed to zero and the displacement since last update to zero as well.Okay?And how does this value get updated is via this.Once this entire execution is done, we will change this value to false.
And now every frame will see that this is not the first update and it will keep calculating the displacement and the displacement speed.I'm recording this part of the video in the end, so you might see some variables that I haven't introduced now.Don't worry, we will get there shortly.Also, let's move this setup into our locomotion's layer space, so I'm going to go in the locomotion and here I will break this and paste it here.

4. Configuring Bones and Wall Detection Logic

Assigning the pelvis, foot, and thigh bones to the stride warping node, then creating an update wall detection function that checks acceleration, velocity threshold, and sliding via dot product.

And this locomotion angle can be let's read from the property access node.We can go in the main anim BP thread safe and we can fetch the locomotion angle.And let's connect this angle to here and this locomotion direction and can also be fetched from the property access node by velocity 2D and we can plug this here.Now, we need to get the locomotion speed that we calculated, so let's just call the property access node again, go for this main anim BP thread save and search for displacement speed.Okay?And also, let's add the bones.First would be the pelvis, second would be the IK foot root.Then I have to add two legs here, so I'll press twice and then I will add the IK foot of left side and the FK, so for that just search for foot left.And then we have the thigh, so thigh left.
And then here we can search for IK foot right.And this one would be foot right.And this one would be thigh right.Okay, so we have all the bones configured.Now leave alpha for now.And now you will see your foot is no longer sliding, instead you are lifting it up.Okay, but now if you go to the wall and start running into it, you see this is the behavior.So I'm going to create a function that is going to detect if I'm running into a wall every frame.So let's go into our ABP base and we will create a function name it update wall detection.And now I'll give a return node.Okay.So first thing to check is whether we are receiving the acceleration or not.When I say acceleration, that means are you holding the keys like WASD to give input to the character so that it can start moving.
So we are storing that in the acceleration 2D.I will bring it out and then I'm going to calculate the magnitude of it in the XY plane of course because we are moving in the XY plane.And I'll check if it is greater than 0.1.That means I'm receiving some input, that is confirmed.Another thing that I want to check is the velocity.Once this acceleration is given in form of input, we will check the velocity.Now, are we even gaining the velocity?Because if you are running into a wall, you will not gain the speed.So that means we have to keep a threshold and that threshold would be let's say 200.So I'll just do less than.So if you are receiving the acceleration and you are not gaining up to 200 uh uh speed, then you are running into some wall or some obstacle that you have in your game.
So, when you are giving the input, let's say by holding the W key, then that acceleration is interpreted by the Unreal Engine and you gain a velocity, but that velocity is not reaching to that magnitude that you haveset in the character movement component's max walk speed.So, that means the speed is getting lost.And how do we detect that is you will start sliding like I showed you.So, as soon as you start sliding, so the sliding is the third check that will tell us that you are actually running into the wall.Because in this case, for example, the W key is pressed, so the angle is at a 0°.But when the sliding begins, the velocity direction changes to a certain angle.That's what we need to detect.So, for this we are going to duplicate these two, and then we will normalize their values first.
And let's do this as well.And once they are normalized, I can do their dot product.So, just go inside vector dot product.This would give us the value, and we will check if it lies in the range of let's say -0.6 to 0.6.And if it is true, then we will have an and boolean that will take all these conditions.Add one more pin here.The first is this, second is this, and third is this.Okay, we are not supposed to return here.We have to set this value into this.And we will then save this value here.And then add that function here.Make sure it is thread safe.And bring it here.Connect with this.And hit compile.Now you know that whether the character is running into the wall or not.

5. Interpolating Stride Alpha and Episode Wrap-Up

Interpolating the stride cycle alpha based on wall detection to reduce warping when sliding, testing the result, enabling debug draw, and closing with next episode plans for jumping.

So, now you go to your locomotion layer space.And now in the locomotion layer space, we can go to our function that is connected with the cycle.And now we can set the stride alpha here.So, we can create a variable here since it has everything to do with this stride warping cycle alpha.And this is going to be float and I can bring this here.And I can connect this to this and return this.And this value is going to be interpolated, so F interp 2.And now whatever the current value is, which is zero initially, but it gets updated.And the target would be the select float.And and we are going to use the property access node and we are going to search for is running into wall.So, if it is running into wall, then A would be the value, so we will say 0.5 reduce the alpha, otherwise keep it one.
So, I'm going to plug this here.And we need to connect this with the target.We need the delta time as well, so we will call this get delta time.And we need to provide the context.So, the context is nothing but this what you're receiving from the sequence player.So, let's do get context and connect this one to this one.This delta time goes here and the interpolation speed, let's say 10.Now, once this is done, we can plug this alpha here and now this will be updated, so we can go to our locomotion cycle and we can get this stride cycle alpha.We can connect this orientation warping, this in the stride warping.Now, once you hit compile and play, and now you can see I'm performing the same animation even I'm running into the wall.If I change my angle, the strafing is working perfectly and you can see the sliding is detected and based on that the alpha has been reduced.
So, it is not like jogging is legs at the same place.Right?So, this was the stride warping.Also, if you want to debug it, you can go in stride warping and then you can play with these enable debug draw.So, I'll just enable the foot adjustment and the foot final.Compile and play again.Now, you can see how my legs have been placed and how the character is moving, how much correction is happening.So, that's it for this video.Do let me know if you have any doubts or suggestions or comments in the comment section, of course.And do like and share it with your friends, subscribe to the channel, and I'll see you in the next episode where we are going to implement the jump and we are finally going to wrap this locomotion chapter andwe will move into the level design.
So, till then, see you.Ta-da.Bye-bye.
Seek backward 5s ←
Longer seek (10s) Shift ←
Play Space Seek forward 5s →
Longer seek (10s) Shift →
0:00 Auto-scroll A Copy link at current time S

Fix Foot Sliding in Unreal Engine 5 with Stride Warping | Master Unreal Series Episode 9