I’m making a sprint cooldown that revolves around running out of stamina and holding the run key. But In my logic I want to force it so that when stamina is down and the cooldown is over, if the player has been holding the shift key the whole time it releases as if hes not holding shift anymore even though he is, so that then he would be walking normal speed and think hmm i need to let go of shift and press it again to run again. Is there anyway to force a release of a keybinding in C++?
Only other thing I can think of doing is just making the logic not run if hes under 10 stamina until he is back at 10 stamina but I’d rather just force a key release.
releasing a key calls the released function and executes some code. stamina running out should call a OutOfBreath() function that executes similar code as the release function. but you might want these functions to be slightly different, so you can reward the player for managing the resource in time rather than letting it deplete completely.
think of zelda: ocarina of time. they had a horse that had a sprint feature that consumed a slowly refilling resource of carrots every time you hit the horse. if you use a few carrots and let it refill, it will refill quickly, but if you use all of the carrots, there is an added delay to punish the player for not managing the resource / beating their horse too much.
some FPS games have a breath holding function that punishes snipers for holding their breath too long, and some games have weapons that overheat from holding the fire button for too long. the point of these features is to make the player tactically immersed in managing a resource, adding a layer of difficulty to balance out the more powerful weapons.
so its a good idea to keep the functionality of these game mechanics separate so you can adjust the reward/punishment of the player choices, giving you an interesting resource management puzzle instead of a button mashing “hold A to win” scenario.