How do I create acceleration upon key press with stamina bar

0 favourites
  • 7 posts
From the Asset Store
Health, Weapon & Rage Bars for your Games. Easy to use & Customize.
  • 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.

  • Shift Is Down   | Set Maximum Speed to 100
    Stamina > 0     | Set Stamina to max(0,Stamina-1)
    
    Stamina =0     | Set Maximum Speed to 50 
    [/code:3uy3y3el]
  • > Shift Is Down   | Set Maximum Speed to 100
    Stamina > 0     | Set Stamina to max(0,Stamina-1)
    
    Stamina =0     | Set Maximum Speed to 50 
    [/code:s242cyf1]
    

    Thank you! I'll try that!

    I need to create "Stamina" as a Global Value right?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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?

  • Every tick         | Set MaximumSpeed to max(50,MaximumSpeed-0.5)
    MaximumSpeed > 50  |
    Shift is Not Down  |
    [/code:2krq6s8c]
    
    Acceleration will be based on similar, or whatever behavior you are using to move in the first place.
  • Every tick         | Set MaximumSpeed to max(50,MaximumSpeed-0.5)
    MaximumSpeed > 50  |
    Shift is Not Down  |
    [/code:2kltjruw]
    
    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.

  • 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.

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