Currently if the player is standing still and holds/presses shift then stamina is going down, I would like this to only happen if the player is moving.
One way you could do it is to check the velocity of the character, if it’s greater than 0 (or 0.1) in any direction that means the character is moving and you should take away stamina.
This would create an error, for example, if the character is falling it would take away stamina as well.
A better way would be to check if the player is holding down W, A, S or D while holding shift. You can do this in blueprints by setting a boolean every time the player presses a key to move, I would call this boolean “IsWalking?”. Now that you know when the character is walking simply put a branch before you want to start running and reducing stamina. If the character “IsWalking?” “Run”.
I’m gonna go for the second method, would I drag off of “Add Movement Input” and set “IsWalking?” to true?
Uhm, I believe “Add Movement Input” is a function. You need to create a boolean variable to store wether the player is holding down W, A, S or D.
To create a Bool, add a variable in the variables section of your characters blueprint, it might be already set to boolean but if its not click on it and it should open a section where you can choose what sort of variable you want. Variables have a little colourful pill that identify them quickly, booleans are red.
There has to be a place in your blueprint that accepts input from the keyboard of the machine. Usually for something like walking it will be a red box on your blueprint graph with a name on it that defines what it does, these are called events and the one your looking for is probably one that has a float variable attached to it, if the float variable it 1 or -1 your character is receiving input from the keyboard 1 should mean that the character is moving forward -1 moving backward.
If this float is != to 0 your character is moving, this means you set your boolean variable “IsWalking?” to true. Type
!= float in the search bar.
Do you understand? If not then attach a picture of your blueprint and Ill happily point all these things out.
Yep just a little different but it doesn’t matter. It will work. Do you need help with anything else?
The only problem that might come of this is if you change your controls in the settings menu and you add new controls like the arrow keys or change from wasd to something else you will need to change it again in this blueprint.
The only thing you need to do is get a Branch and before the sprint mechanics execute check if the character is walking.
I did that. Also, I tried to use my input axis’ but they don’t give me a “Pressed” and “Released” function. As for anything else I need help with, I would like the controls to smoother, for example, when I release a key the player just stops in their tracks.
If you want to use the input axis all you need to do is drag out from the float it has and check if it’s equal to 0, if it is then the character is not moving, anything else means that the character is moving/receiving input.
To make it smoother go into CharacterMovement (inherited) and search for Deceleration.
If you have solved your issue with my help then please mark my answer as the correct answer please.
I tried to mark it as the correct answer before but couldn’t figure it out, now it is set.
Thanks a lot, did the Decelerate work?
I’m not sure what to edit/don’t under what I’m looking at. I know what deceleration is though.
I changed the values and it didn’t appear to do anything.
You gotta really change it a lot to notice anything, and make sure to change the deceleration for walking.
Should I raise or lower it? I set it to 0.0 and it didn’t change.
Ok I just tried it and what you have to do is check a box that says “Use Separate Braking Friction”. You can read about what it does when you scroll over it.
That works, thank you.