How do I create acceleration upon key press with stamina bar

Get help using Construct 2

Post » Sat Apr 23, 2016 4:25 am

Hello. This is my first post. :) I watched many tutorials but never found this. Perhaps there is in some advanced complete video tutorials, but I'm still at beginning of my game.

So here is what I want to do. Please help me if possible, to at least give me an idea. ^^

When press SHIFT, object ACCELERATE till a MAXIMUM VELOCITY.

For example, if normal velocity is 50, I want that upon SHIFT pressed, velocity slowly increases until 100 and stops. And for all the time that SHIFT is pressed, there will be a STAMINA BAR decreasing. When STAMINA BAR is at 0, object will decelerate until reach his 50 velocity again.

SHIFT can be pressed at any time, even if STAMINA BAR is at middle.

Also, if possible, I wonder if its possible to add a animation triggered by that. Like a turbo/nitro animation.
B
5
S
2
Posts: 7
Reputation: 439

Post » Sat Apr 23, 2016 5:21 am

Code: Select all
Shift Is Down   | Set Maximum Speed to 100
Stamina > 0     | Set Stamina to max(0,Stamina-1)

Stamina =0     | Set Maximum Speed to 50
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Sat Apr 23, 2016 10:08 pm

oosyrag wrote:
Code: Select all
Shift Is Down   | Set Maximum Speed to 100
Stamina > 0     | Set Stamina to max(0,Stamina-1)

Stamina =0     | Set Maximum Speed to 50


Thank you! I'll try that!

I need to create "Stamina" as a Global Value right?
B
5
S
2
Posts: 7
Reputation: 439

Post » Sat Apr 23, 2016 11:25 pm

One more question, how do I make the acceleration and deceleration smooth?

When I release shift, the Player instantly changes its speed. How to make so he slowly lose speed?
B
5
S
2
Posts: 7
Reputation: 439

Post » Sun Apr 24, 2016 3:18 am

Code: Select all
Every tick         | Set MaximumSpeed to max(50,MaximumSpeed-0.5)
MaximumSpeed > 50  |
Shift is Not Down  |


Acceleration will be based on similar, or whatever behavior you are using to move in the first place.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Sun Apr 24, 2016 3:39 am

oosyrag wrote:
Code: Select all
Every tick         | Set MaximumSpeed to max(50,MaximumSpeed-0.5)
MaximumSpeed > 50  |
Shift is Not Down  |


Acceleration will be based on similar, or whatever behavior you are using to move in the first place.



Thank you very much. Could you post a printscreen of the code you posted above? Only so I can see what is condition, event, etc.

Sorry I'm new to Construct.
B
5
S
2
Posts: 7
Reputation: 439

Post » Sun Apr 24, 2016 6:36 am

Here is a rough capx.

https://www.dropbox.com/s/7u806ikrra0xg ... .capx?dl=0

You'll need to work out some things like how you want the speed to be when they keep trying to sprint near 0 stamina, or the rate of stamina depletion and regeneration, and also if you want to use dt.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 62 guests