Problem With MaxWalkSpeed For Wounded State

(I apologize in advance if the solution to this is super obvious or if this question has been answered elsewhere.)

Currently, I have a character with a default “calm” state for which I have (more-or-less) successfully gotten him to properly idle, walk, run, crouch, and jump. I’m currently trying to add an additional “wounded” state for idling/walking/running when his HP drops below 40 and after some struggling have finally managed to get him to swap to that state in regards to animations. For some reason, however, I can’t for the life of me get his movement speed to reflect the change in speed that I want him to have in his limping “wounded” state.

Before I started trying to add this new state, this was all that I really needed in my character BP to get things working speed-wise. In the CharacterMovement component details, the Max Walk Speed is set to 500 while the Max Walk Speed While Crouched option is set to 200.

I created a variable for whether or not my character is limping, shown below. (I had actually already created this variable once before for the purposes of actually making the character transition to his wounded state, but it never worked and I instead had to straight-up just tell the State Machine to use his Current Total Health variable instead.)

276486-movement-2.png

With that variable, I attempted this setup and got no results (and trust me, I tried it with some pretty far-out speeds to make sure I wasn’t being confused by the speed change being too small).

When that didn’t work, I removed the Character Movement component, branches, and Set Max Walk Speed nodes from the Walk action and tried this.

Still nothing. Please help?

Hopefully this isn’t too early for a bump? I’m still having problems with this.

So I can see a few things here that could be giving you grief with this. The easiest way around it is to set the Max Walk Speed during your event that sets the Is Player Injured? Bool. Right after setting that bool to true or false, add a Set Max Walk Speed node with the value that should be used in that case.

You could also do that with the crouch variable, though if you want to have both impact the speed when combines (injured and crouching) you may be better off using a Injury Walk Modifier and a Crouch Modifier set up as floats and then add, subtract or multiply (depending on how you want to handle the values) these to the walk speed when setting a new walk speed.

Darn. That didn’t work either. Thank you for leaving your suggestion anyway.

no worries sorry I couldn’t be more help :frowning:

Thank you so much for answering, but I’m afraid neither of those suggestions gave me any results. Any other ideas?

Hi. I have a suggestion. I am new to UE4 so I don’t really know if this is the best way of going about it, but I thought I would put it out there anyway. Is it possible to use an axis mapping for movement and then modify the axis value using a function, depending on whether you are injured?

Sort of like this:

And then use the “Adjust Forward Axis” Function to adjust the axis input, like this:

Idk if its the proper way of going about things, but it seems to work for me to modify speeds for different states

Is the “Is Player Injured?” event above being called every time damage is applied to the player and then again every time the player is healed? If not the event will be ignored for the most part.

Ideally, during the sections for removing and restoring health, they’d do a quick check using that event after the health adjustment is made so that the injured check is done consistently. If you have it that way, then having the speed set depending on the result of that check would do it.

What value did you use with the injured speed modifier? The axis value will be between 0 and 1, so if you set the injured speed modifier to like 0.5, that should half the axis value.

Well, I didn’t know the axis value range tidbit so I initially tried using the modifier to subtract 100 from the axis value (thinking it was like the Max Walk Speed float), but after that failed I did try using the modifier to multiply the axis value by .1 (to try and get a really obvious speed change) based off of your example.

Hmm yea strange, multiplying the axis value by .1 should reduce the speed to 1/10th of the original axis value. Sorry :frowning: not sure why that doesn’t work

I actually haven’t even gotten around to implementing any damaging or healing events yet (unless you count having events to add/subtract 5 hit points when pressing certain keys for testing purposes). I have no idea how often the event to check for injury is being called, but I guess it probably is being called constantly. Looks like I need to get the damaging/healing stuff in before this part will function properly…

Since you have a testing setup to alter the values, you could have that check run every time you make an adjustment to the health using those keys to verify if it’s working or not :slight_smile:

I finally got it! I have to extend huge thanks to both of you because you actually ended up having half of my solution each!

So after moving the injury check over to my health modification test events as per SithHunter’s suggestion, I was still not getting any results. So then I retried Stwyford’s Adjust Forward Axis function, and that finally did the trick. Here’s the setup I ended up with:

Stwyford’s method uses speed modifiers with values set as percentages, but since I had concrete speed amounts that I wanted my character to move at I created float variables with the desired values (i.e. 200 for walking when uninjured) and then divided that by 500 (the maximum speed, set for running when uninjured) to give me whatever obscure percentage would get the desired result and then clamped the Axis Value accordingly. I also had to create an Adjust Right Axis function that looks exactly the same.

I’ve already added another Boolean for the character being extra injured (when his health is less than 20) that reduces his speed even further (although he’s so slow at that point that I didn’t bother making any difference between his running and walking since either way he’s limping along at a snail’s pace). Ideally I’d like to be able to gradually reduce his speed as his health drops from 40 to 20, but I’m just so relieved to have this much working that I think it can wait until a later date. I mean… Unless somebody has any ideas for that too?

But anyway, thanks again to both of you. You’re life savers!

Awesome! I’m happy you got it working :slight_smile:

Nice work! Glad to hear you got things working and always happy to help out.