Currently implementing a stamina system, after getting a few things on the hud to display. And so far it is going well. I may add a tutorial for this a bit later once I’ve got it looking a bit more neater and set up to be more functional… Pun intended.
The idea is that when you sprint, your stamina drains. When standing still, it recovers twice as fast (give or take some agility/endurance factors), than you would be moving.
It also doesn’t help that if you hold the sprint button down and you aren’t moving, you are wasting stamina energy.
To get around these two problems, i figured out this.
I thought this would help others, as you can detect whether something is moving in a similar way, toggle events if you stand still long enough or just generally what ever else you want to happen if your moving or not.
How it works:
It grabs the movement component and gets its velocity. I initially had it into a break vector and lots of != checks and then slapped myself for being silly so now its just if the vector is bigger than 0 (since when you move its a “+” or “-” vector). Then you set movement to true/false. The tick checks it constantly and the print string barrages you with lots of nice debug.