I Made a Stamina system. that need fixes

I made a stamina system for a multiplayer survival game so when I hold the shift key I start running and the stamina drains but when I let go of the hold shift it still drains and I have to stop, and it start going back but i want it to regenerate while i walk after letting go in shift key

Sprint

Sprint posted by pevpev | blueprintUE | PasteBin For Unreal Engine

Drain stamina attached to Movement Input

Drain stamina attached to Movement Input posted by pevpev | blueprintUE | PasteBin For Unreal Engine

Drain and regen stamina event graph

Drain and regen stamina event graph posted by pevpev | blueprintUE | PasteBin For Unreal Engine

FRegenStam

FRegenStam posted by pevpev | blueprintUE | PasteBin For Unreal Engine

FDrainStam

FDrainStam posted by pevpev | blueprintUE | PasteBin For Unreal Engine

Hello There,

I skim through the scipts,

So there are multiple culprits here in the scripts but what essentially happenning : Player’s stamina after reaching less then 0.25 marks bStamLow so after a certain value it goes lower but never stops draining (probably stuck at close to 0) since when you even let go shift it fails on input side here :

This never triggers sprinting off bool. Even though speed seems to change cause you set those on the Stamina function already.

Btw there is a much effective and a simpler way of doing this, I see that there is many bools making debugging a bit hard. There can be some logic gates which functions does what and that would be much easier to craft also much more efficient.

1- Input : Let’s treat the player input just player wants to do something. Like bWantsToSprint. Making bool like this is basically telling yourself and systems, player tries to sprint but we don’t know if they are sprinting or not or their speed. So I suggest you remove speed functions from there. bWantsToSprint true or false.

2- Handling : So after player wants to spring we can do things on the tick easiest way, it’s not a big load and its better sometimes to handle movement on tick since your design dependent on stamina currency / attribute

What we do , we check if this wants sprint and have stamina enough we decrease and set movement mode. If not we regen / give stamina and set movement mode.

Additionally before function ends /exists we consider stamina status (StaminaLow) if Low set movement mode, if very low again set movement mode. Before we exit status we select the correct movement mode speed and set character.

Character movement is replicated by default so you don’t have to too much worry about it. However if you want for some reason you can do like this ( you already do a RPC call)

UI can be standalone, we don’t have to tell can listen.

Should be acting something like below

There is other ways to handle this, including service, GAS Ability etc. Let me know if this is valuable. Just wanted to point out that it can be more simpler with respect to what you have done so far however the bug mentioned in the first paragraph can also be fixed.

Also don’t hesitate to articulate design behaviour if you looking for something specific in design.

  • Regen with different aspects
  • Regen curves
  • Drain / cost only when can sprint.
  • Drain / cost with different aspects

etc.

2 Likes

I do not know anything about GAS but i will look into it. Also, I was wondering did i send you this picture or did you put it as I was looking at a few different stamina blueprints so I’m not sure if i sent you the wrong thing Also thank you for the help it means a lot

No worries, I just take a look at your blueprint snippet links. That screen shot (Input->bWantsToSprint) is something I put together for you. If you want you can create an additional function/macro infront of it as CanSprint() and check crouch etc. before marking bWantsToSprint to match your already existing systems.

Take a look around especially how I break down seperation between systems. Like input not directly interfering with the movement itself. UI is just listening we don’t have to tell something to UI.

GAS can be overkill for one simple thing however it can serve you good in long term in terms of its design pillars and understanding.

Simply to Recap

  1. Input → Player wants to do something.
  2. Handle → What can be done at that moment of gameplay. (Change walking speeds in your case)
  3. Execute → Commit change (Spend or give currency, mark low currency etc)

As you can see I handle Regeneration/Cost in the beginning however cost is better be in the end also since action than reaction. I just wanted to replicate your design to demonstrate, nothing wrong with yours its just more complex than it normally can be. Regeneration can be also only after low stamina mark removed to be better understandable by player.

First off thank you for the help it means a lot. I was not sure if you want me to get rid of it also, I’m not sure if it matters, I’m using 5.7 my apologies for not saying sooner

This is my sprint

Movement Input

Movement Input posted by pevpev | blueprintUE | PasteBin For Unreal Engine

sprint

sprint posted by pevpev | blueprintUE | PasteBin For Unreal Engine

Drain and regen stamina

Drain and regen stamina posted by pevpev | blueprintUE | PasteBin For Unreal Engine

HandleSprint

HandleSprint posted by pevpev | blueprintUE | PasteBin For Unreal Engine

W_PlayerStatsWindow also this is where my stats that show my sprinting going down witch would show on my W_DefaultHUDLayout

W_PlayerStatsWindow posted by pevpev | blueprintUE | PasteBin For Unreal Engine

1 Like

No worries my pleasure, community / forum is what it is for.

So you don’t need this anymore actually if you try to replicate what I demonstrated.

Cause we check stamina->cost on tick. Meaning if on tick something matches will already cost stamina.

Let me walk you through a better version step by step. A working example design of what you want. Both examples should work its just reordering cause of design aspects.

1- Can I sprint? if conditions pass we mark as wants to sprint

You can do whatever condition you have. Like crouch, aim, ads ..

2-Handle Sprint

At that moment what can we do? Output integer of movement mode.

3- Execute

on 0, 1, 3, I decrease stamina . on 2 we give stamina
However additional design aspect if player goes low stamina and still tries sprint we even cost more, if stops sprint at that moment (low stamina) → we regen but less (0.25) till its normal stamina then goes movement mode 2 after a while and regenerates stamina regularly.

Here is full snippets


Can be many things however I felt like if player is low stamina, they have to decide wheter they should keep pushing or not to sprint. Since now we have outcomes if we push sprint.. it costs more however we still move.. You can even give that a movement mode like 4 and have a different speed.

Imagine this is a horse racing or player is riding horse escaping from enemy. It’s on players hands strategically when to sprint when to rest horse.

try to replicate these and if you want to push further aspects, we can push together.

  • Cost more stamina on climbing less on flat surfaces
  • Time passed with sprint. Curves over time costs etc.

I was not sure if you wanted me to get rid of the drain stamina thing so I just unplugged them for now but when I move I move very slowly and I notice there are two function called cost stamina and stamina cost and I was wondering if I was missing something as I cannot find it also here a picture of my can sprint

Call your custom event here.

My apologies for not responding but I’m sad to say it was not working so I’m going to go back to my old way and come back to it later thank for helping and have a great day

1 Like