I'm trying to fix the stamina system in my game, and one issue I have come across is that the stamina_loss signal in the code below will emit based on the framerate of the game because the sprinting mechanic is inside of the _process(delta) since it needs to check if the sprint key is being pressed or not. The issue is, the signal connects to the game HUD in the second image where the stamina is being kept track of, and every time the signal emits 2 is being taken away from the current stamina var. Since the signals emit based on the framerate this results in inconsistent stamina loss which is a big issue. Is there anyway I can force the signals to emit at the same time using delta or some other function? Sorry if this paragraph was a bit confusing.

  • Your issue seems to have less to do with signals and more to do with decrementing an integer by a fixed amount every frame. Use a float for your stamina and just round it down if you want to display it as an int in your UI. Figure out the stamina per second you want to use, and multiply that by delta. NEVER depend on the framerate to determine how fast a variable changes. It is completely unreliable.

You can limit the frame rate to like 15 per second so you have synchronization. Its a good practice by the way, to do this on almost everything you do so you improve performance.

Your issue seems to have less to do with signals and more to do with decrementing an integer by a fixed amount every frame. Use a float for your stamina and just round it down if you want to display it as an int in your UI. Figure out the stamina per second you want to use, and multiply that by delta. NEVER depend on the framerate to determine how fast a variable changes. It is completely unreliable.

    AnnoyingCat Yes, you either need to use delta to adjust the stamina loss depending on the varying frame rate or put this code into _physics_process() because that one gets called with a fixed frequency (for example 60 times per second). Although ideally you should still use delta.

    But you never know how often _process() gets called. A good way to make sure your game is not frame rate dependent is to disable VSync in your project settings to let your game run with for example 1000+ FPS.