I’ve attached an image that might help you understand how to use Blueprints to accomplish something like this. Right click to view the image in full resolution.
I’ll explain it here in text, and if you have any questions please ask.
First I use a boolean variable “IsSprinting” to keep track of whether or not the sprinting key is currently being pressed. I use a “FlipFlop” node here. The “FlipFlop” node will alternate between A and B each time it receives input. So when shift is pressed, it fires off A, which sets “IsSprinting” variable to true. Then when shift is released, it fires B, which sets “IsSprinting” to false. Now we can check the variable “IsSprinting” to see the state of the sprint key anywhere in our blueprint.
Next, I use the “Event Tick” node to check every frame if “IsSprinting” is true (shift is pressed), and also if “Stamina” is greater than zero. They both must be true in order for the “AND” node to output true. If these conditions are true (checked with a branch node), then we set “Speed” variable equal to our “Sprint Speed” variable. If they’re false, we set “Speed” to “Walk Speed” variable. These variables have default values set in the details panel below the “My Blueprint” section.
Please keep in mind that this is not a complete or optimized solution.
Some things wrong with this example:
- Speed is being set every frame,
when really it only needs to happen
once per key press/release. - Stamina isn’t being reduced/recovered
- Speed isn’t being applied to the character
Hopefully this can get you going on the right track. There are many different ways to do this, and I encourage you to check out all the fantastic Blueprint tutorials on the Unreal Engine Youtube channel.
