Need help implementing stamina for sprint mechanic

I have a sprint setup that works in the My Character blueprint, but I’m trying to add stamina to limit the use of the sprint. I have a stamina variable with a range of 0-100 and a default value of 100, and a walk speed variable with a default value of 200. My current setup has no effect even when I take out my attempt of regeneration and up the value to decrease the stamina by.

Whats Up Zi,

Your current setup would add stamina, and allow sprinting indefinitely. I tried setting the float range, and watching the variable in debug tells me it ignores this limitation. Also you say you aren’t getting an affect. No affect at all? It looks as if it would at least make you sprint. Here is a setup I built and play tested. I created this setup for a tutorial, let me know how it works for you.

Note: Simply swap out my InputAxis Thurst for your InputAxis Sprint, and swap Left Shift for the key event for Sprint.

Update: Fixed bug I noticed.

Peace

Hey there!

This is my first post, so I use this to shout out a big HELLO to everybody.

I am an animator and have absolutely no clue about coding or even scripting, however blueprint seems to be a challenge I am willing to take. And so far it’s good fun.

It’s fun to see how many different approaches are posted here to do a Sprint-Logic. I have been trying to figure something out myself. In the end I used part of zuch06980 aproach to get rid of a glitch I had.

Here is what came out in the end. It seems to work, but I would be glad to get some kind of feedback whether you guys see something terribly bad about my setup.

I like what you’ve done. The approach is simple and direct. Do a good job at keeping clutter to a minimum. The velocity check worries me a little considering they could be falling or been hit by any outside force which would reduce stamina. The delay on subtraction / addition makes it slightly more difficult to calculate stamina lost per second, but not impossible. Otherwise good job.

Thanks everyone, all of these suggestions helped me to get a result.

Hey dude. I tried implimenting your stamina system into something I’m working on but like SilentX said you loose Stamina as you fall. Any ideas on how to fix this?

Hey,

yeah, this is a problem… It works for me, as I don’t fall at all in my little project, but I understand that this can be a dealbreaker for other projects. You could try to stop decreasing the stamina while the character is in-air. Somewhere in the character movement component you should find a test for something like “is in air”. Maybe you can use this as a bool variable and use this as condition for the stamina drain by using a branch node.

But that was just shooting from the hip. However that is what I would try.

I would be happy to see how you solved it in the end :slight_smile:

Cheers!

So I use a simple bool checking if the pawn mesh overlaps ladscape. Of True use stamina if false don’t use it