Download

How can i create sprint speed and walking speed with blueprints?

So far i have managed to do exactly what i just asked. However there is a problem. So far my logic runs like this:

I have an action input for running, and it uses Shift key.

Then, in the character blueprint, i have a boolean check if it is pressed or not.

If Run action is not pressed, MoveForward Axis value will be divided by specific number to create “Walking speed”.

If Run action is pressed, MoveForward axis value will be default.

So far my logic is working, however there is a problem. When for example W and A are both pressed, movement speed will get doubled. I am trying to create a boolean whether both are pressed or not, the create specific movement speed to deal with the issue. But my problem with it is this:

de4da8cf4f06703ffa0db48369fbe3238e815c6d.jpeg

Is the situation in the picture even possible? InputAxis event does not have a RELEASED -statement.
How can i create a Set boolean for InputAxis being released? So far i have not figured out any way. And if the situation should work in the picture, please tell me! :slight_smile:

If there is better way to create walking speed as a default, and the sprint speed when shift is pressed, please tell me!

So far the whole mess looks like this:
1945ac9e20c1e9b218aa94996e884cfeb6de27c1.jpeg

I think you’re over complicating something that is simple to do.

The way you should approach this, imho, is to have a default walk speed (the character controller already has a default walk speed), you should leave this alone.
Sprinting should be a modifier, that while pressed, modifies the current walk speed by doubling it (simulating a faster run or sprint)
When releasing the sprint key, the walk speed should be returned back to the original default speed when the game began.
To do this, on Begin Play, store the default walk speed of the movement component of the character to a custom variable. Then you can always revert to that default walk speed everytime sprinting ends (i.e. when player releases sprint key, or when player runs out of stamina, etc.)

You can actually grab the forward vector of the player, so you can make a check with a branch that checks:

  1. is player moving forward?
  2. is player moving at least a few unreal units per second (i.e. walking more than 1 MPH)?

If so, then you could allow “sprinting” functionality.

This is pretty easy to setup, I’ve done it dozens of times. Try to simplify the problem in your mind first before tackling it. Good luck!

Thanks for quick answer! Actually i think this thread is worth to be deleted, because i just figured out a whole A LOT easier way the create this.

So what was the reason that i didn’t realize this? I couldn’t find a “Max Walk Speed” node, because i had context sensitivity checked. I really think these kind of things should be context sensitive within character blueprint!

So the solution was fairly simple, and it eliminates the problem i had with speed doubling:

solution.jpg

Still i would want to know how to create that released boolean check from input axis -event! :slight_smile:

-Next thing is to create a fatigue system —>