Stop movement speed of characters when hit the wall and animations when hit the wall?

I’m new to Unreal Engine 4, and I started to learn about 4 days ago, and now i’m trying to make running system with parkour elements but I’m stucked when character hit the wall but max walk speed( I think) still keep it value but not decrease to 0 because hit the wall XD.

I created a blueprint when player run depended on tps template, then stamina will decrease and camera will start shaking, but the problem when character hit the wall, the stamina still decrease and camera still shaking.

So I think the problem because the character movement speed still in max value. Can u guys help me stop the character movement speed when touch the wall? and add some animation when character hit a wall?


Imgur

Imgur

it’s because your logic says if the player pressed the button to run, so he is running(is run on = true) so i will reduce the stamina, but actually if the player press the key to run he is TRYING TO run, i suggest you to remove stamina based in the player velocity instead of removing 1 at every 0.2 seconds from stamina try to remove the speed / max walk speed (so if he is trying to run against a wall the speed will be 0 and the stamina won’t be removed), you can type “get velocity” it will return the actors velocity and it’s a vector, to get the actual speed grab the returned vector from velocity and type “get length”.

have in mind: speed = length of the velocity vector.
this is just a workaround, but you can achieve a better solution keeping in mind that you should also take the actual speed in count not just the max speed.

and maybe you know it, but you don’t need to change the max speed every frame to have the “accelerating” feeling, you can also set “max acceleration” to a lower value, “max acceleration” is under character’s movement general settings.

I’ll try that out. Tks for the answer :smiley:

I tried velocity and length you said, it’s can fix a few bug in my blueprint, but when the character run into the wall, its still keep counting down. So I think the problem here is because the movement input or in ThirdPerson_BP. xD

This is clearly quite old but I found this looking for a solution and ended up coming up with one I figured I’d share for anyone else looking into this. The problem seems to be that getting the velocity really returns the “expected velocity”. I came looking for a “complex” solution if you will, but the easiest and unfortunately only way I came up with to solve this would be to scan in front of the character for a wall manually. Simply add a box collision slightly protruding the front of the character, on begin overlap lock sprint, on end overlap unlock sprint. I however used a capsule trace. I did this so I could call it from a macro setup to return true or false similar to a branch just for cleanliness as I don’t enjoy having a bunch of overlap events on my graph.

To do this you want get velocity vector length <= walk speed from walk speed blend and if you want it to really work base it of the forward vector that looks good. Do this by hooking up a print string to show the vector length. Pay attention to the variable when you feel like your character should begin using stamina. Set <= bottom input as the number you found. I recommend changing your run speed animation to a speed that can accommodate your or making the character use stamina at the same speed the character begins to lean forward in the idle walk run blend space.

Regardless of a characters “max walk speed” a character will not have velocity if it is not moving.

IF (speed >= N) { Drain Stamina }
IF (Stamina <= X) { Disable Sprint .. aka reduce max walk speed }