Stamina Regen problem

0 favourites
  • Hi!

    I'm presently adding a stamina system in my project and I ran into a problem: Once the Player jumps, stamina begins to recover. I tried different things but nothing seems to work and I'm sure I'm overlooking something.

    Here is the link to the capx file. Thanks in advance!

    https://www.dropbox.com/s/gassgl8hwgvfyqk/test_02.capx

    Cheers

    controls: right and left arrows to run, up arrow to jump.

  • Did you try to make a global variable that is set to 1 when you press the jump key and, while the global variable is 1, add x amount of stamina to your stamina bar every tick?

    To stop stamina regen, when stamina bar is full or player gets hit, set your global variable to 0.

    In my head that works, but I'm not near my computer with C2 on it, so I can't test it.

    Maybe someone else has a better suggestion though...

    EDIT: I had health written, but meant stamina.

  • Hey thanks for the reply, now its kinda late but Ill be trying that tomorrow after work. I didn't do it exactly the same way so chances are that this might work better. Thanks!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Ok, so I tried using a global variable and set it initially to 0 and then to 1 once once the character is running. Then, once it jumps set it back to 0. But I still have the same problem. There's no problem with the stamina recovery until I jump. But I still cant figure out what's causing that. All I know is that somehow after jumping the player is not going back to its initial state.

  • Actually I discovered that after doing a walljump, everything goes back to normal. Even weirder lol

  • Shameless bump. Anyone?

  • I can't fix it for you now, but here is my tip. Start using subevents, your events are probably conflicting. Think of what is more important first and start sub dividing the other events. For example..

    |-PlayerDectect (x) is moving > Add stamina

    |

    |_-Else

    | |_PlayerDetect is on floor

    | | |____- PlayerDetect is Running > Subtract Stamina

    | |

    | |_ Else

    | |___ PlayerDetect is Falling or is Jumping or is WallGliding > Add stamina

    Another tip, don't update the width of the stamina bar directly, create a variable for stamina and add and subtract values of that variable, then update the bar's width based on that variable

    bar set width to maxBarWidth * (currentStamina/maxStamina)

  • caiorosisca

    Thanks for the tips and great help. This helped me understand a few features and re-organize my code.

    The problem was indeed really small and mostly because of the order everything was.

    Thanks!!

    Cheers

  • caiorosisca

    Just one small question. I understand that maxStamina is a global variable, but how do I use currentStamina?

    Presently, the stamina consumption while the player runs is a simple runStaminaCost * Time, so lets say I run a bit, how exactly do I update this into the Stam Bar?

    Cheers

  • Wouldn't that be a simple subtract runstaminacost*time from the currentstamina?

    so every 0.1 second if player is running subtract runstaminacost from currentstamina..

    you probably have to adjust the value of the runstaminacost for this, but that should be simple..

  • Exactly, just use your current equation and suctract from currentStamina.

    Also don't forget to limit min and maximum stamina after all calculations are done, if currentStamina < 0, currentStamina = 0, else if currentStamina > maxStamina, currentStamina = maxStamina.

  • Saw your comment after I had posted! Thanks, now it makes sense.

    Thanks!

  • I updated the main post since I don't seem to be getting anywhere. I can get it working directly on the bar, but not by using variables.

  • looking at the debugger currentstamina goes directly to 0 when moving..

    Also I can see you are setting the width of the staminabar in th stamina-consumption eventsheet and in the hud event sheet..

    it makes it very unclear for me to get an overview of what the actions should be..

  • LittleStain, you are right. I added the bar update with the values twice. Should instead stay in the HUD sheet. My idea is to deal with the values (since later they will be modified by a simple level up system). The way I understand it, I should add my variables and then update the bar with the values based off currentStamina and maxStamina.

    The reason I added a Stamina Consumption sheet is mainly because every action uses a different amount of stamina. Some actions use a constant value and others such as running are based on the duration of the action.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)