How do I use the same Key Button for doing two things

0 favourites
  • 5 posts
From the Asset Store
This is a Dungeon Master tool & the 1st of 12 Combat Engines from the Building Combat Engines for Browser Games workshop
  • Hi guys, im trying to use the same Keyboard Button to do tow different things. If i mantain pressed the x button, timescale should go to 0.5, but if i just press the x button but not held it down i should do a Dash. I know how to do te two things with different buttons, but i need to use the same button if pressed but not held down, and if held down.

    X pressed but not held down ---> Dash

    X pressed and held down ----> Set Timescale to 0.5 as long as the X button is held down (Dont do dash if held down)

  • Hmm, this might not be the best solution but off the top of my head maybe add a variable as a kind of timer and use it to gauge how long the key is pressed. Something like,

    X is pressed -> Add 1 to Variable

    X is released + Variable<20 --> Dash (i.e. if you tap the key without letting Variable build up to 20, you dash)

    Variable>20 --> Slow time (so if you hold X down for a bit, timescale changes)

    X not pressed and Variable>0 --> Set Variable to 0 (to reset)

    And then adjust the value at which time slows to strike the balance you need.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The solution provided sounds correct and it is called a buffering input.

    Although you should actually reset your variable to 0 in the "On release" no matter what, using a blank event for example.

    Key is pressed => Add dt to variable (Delta Time)

    Key on release

    ... Variable < 0.5 => Do dash

    ... Variable => 0.5 => Do Slow time

    ... (blank) => Reset Variable

    This way your variable will only build up when you are pressing the key.

    And the time there are akin to pressing the key for half a second. Using dt, you are getting an exact value of 1 added each second the key is down in a consistent manner over all computers.

  • Thanks to both, i managed to make it work C:!

  • Good answer, stopped my player using his pickaxe as soon as i pushed the button.

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