Stamina Regen problem

Get help using Construct 2

Post » Sun Jul 13, 2014 6:21 pm

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.
B
43
S
12
G
14
Posts: 488
Reputation: 10,570

Post » Sun Jul 13, 2014 8:33 pm

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. :P
Be sure to check out my Metroidvania game, A Hole in the Earth
B
59
S
24
G
3
Posts: 359
Reputation: 5,683

Post » Mon Jul 14, 2014 2:12 am

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!
B
43
S
12
G
14
Posts: 488
Reputation: 10,570

Post » Mon Jul 14, 2014 10:57 pm

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.
B
43
S
12
G
14
Posts: 488
Reputation: 10,570

Post » Mon Jul 14, 2014 11:18 pm

Actually I discovered that after doing a walljump, everything goes back to normal. Even weirder lol
B
43
S
12
G
14
Posts: 488
Reputation: 10,570

Post » Tue Jul 15, 2014 5:09 pm

Shameless bump. Anyone?
B
43
S
12
G
14
Posts: 488
Reputation: 10,570

Post » Tue Jul 15, 2014 6:56 pm

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)
Please tag me with @caiorosisca if your post is refering to me :). I don't always follow the topics I answer.
B
11
S
4
G
1
Posts: 272
Reputation: 1,643

Post » Tue Jul 15, 2014 10:31 pm

@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
B
43
S
12
G
14
Posts: 488
Reputation: 10,570

Post » Thu Jul 17, 2014 11:33 am

@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
B
43
S
12
G
14
Posts: 488
Reputation: 10,570

Post » Thu Jul 17, 2014 11:38 am

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..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Next

Return to How do I....?

Who is online

Users browsing this forum: matriax, plinkie and 1 guest