How do I add a very short timer that can be used infinitely.

0 favourites
  • 6 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • I'm pretty new to Construct and I'm trying to figure out how I make a very short timer. I have a dashing function almost working, it increases max speed by 10 times when shift is pressed and sets vector x to that speed but I want this to last about half a second or so before not working again for a second or so.

    My main problem here is the time of the dash I can get the cooldown and everything working but I want to delay and make simply pressing shift boost you forward really quickly and then lower your max speed back down to normal and I'm having issues doing this

    Tagged:

  • to add timers like this to things i usually use a variable and then have an event that sets to variable to the time you want and an event that continuously removes time from that variable.

    for example: You make an instance variable on you player called "boosting"

    then for example

    When shift key pressed - set "boosting" to 0.5 (this gives you the amount of time you are after)

    then you link the action you are seeking to that variable being greater than 0. e.g.

    If player.boosting > 0 - set max speed to 100(or whatever u want)

    Inside this event you have a sub event that handles the countdown of the variable

    so sub event: -- every 0.1sec subtract 0.1 from player.boosting

    then finally you have an event that resets the action to normal when the counter has run down

    If player.boosting =<0 - set max speed to 50(or standard speed)

    Here is an example that i did for someone else of the same technique, that means that for 5 seconds after a player has overlapped the blood pool, they will produce bloody footsteps while moving. Same method.

    1drv.ms/u/s!AkmrWgxeuxlKhIcKKuFgyNMlgcROYw

  • to add timers like this to things i usually use a variable and then have an event that sets to variable to the time you want and an event that continuously removes time from that variable.

    for example: You make an instance variable on you player called "boosting"

    then for example

    When shift key pressed - set "boosting" to 0.5 (this gives you the amount of time you are after)

    then you link the action you are seeking to that variable being greater than 0. e.g.

    If player.boosting > 0 - set max speed to 100(or whatever u want)

    Inside this event you have a sub event that handles the countdown of the variable

    so sub event: -- every 0.1sec subtract 0.1 from player.boosting

    then finally you have an event that resets the action to normal when the counter has run down

    If player.boosting =<0 - set max speed to 50(or standard speed)

    Here is an example that i did for someone else of the same technique, that means that for 5 seconds after a player has overlapped the blood pool, they will produce bloody footsteps while moving. Same method.

    https://1drv.ms/u/s!AkmrWgxeuxlKhIcKKuFgyNMlgcROYw?e=EVX3Wd

    And also to add to this, you can also use the Timer behavior. When you dash, set timer with the tag "dash" and duration of the dash.

    If "dash" timer is running, set speed to dash speed.

    if "dash" timer NOT running, set speed to lerp() back to normal speed.

    You can also add that only if the "dash" timer is NOT running, you can hit "shift" to dash.

  • > to add timers like this to things i usually use a variable and then have an event that sets to variable to the time you want and an event that continuously removes time from that variable.

    >

    > for example: You make an instance variable on you player called "boosting"

    >

    > then for example

    >

    > When shift key pressed - set "boosting" to 0.5 (this gives you the amount of time you are after)

    >

    > then you link the action you are seeking to that variable being greater than 0. e.g.

    >

    > If player.boosting > 0 - set max speed to 100(or whatever u want)

    >

    > Inside this event you have a sub event that handles the countdown of the variable

    >

    > so sub event: -- every 0.1sec subtract 0.1 from player.boosting

    >

    > then finally you have an event that resets the action to normal when the counter has run down

    >

    > If player.boosting =<0 - set max speed to 50(or standard speed)

    >

    > Here is an example that i did for someone else of the same technique, that means that for 5 seconds after a player has overlapped the blood pool, they will produce bloody footsteps while moving. Same method.

    >

    > 1drv.ms/u/s!AkmrWgxeuxlKhIcKKuFgyNMlgcROYw

    And also to add to this, you can also use the Timer behavior. When you dash, set timer with the tag "dash" and duration of the dash.

    If "dash" timer is running, set speed to dash speed.

    if "dash" timer NOT running, set speed to lerp() back to normal speed.

    You can also add that only if the "dash" timer is NOT running, you can hit "shift" to dash.

    I have this working but I'm wondering if there is a way to slow the deceleration by the lerp down.

  • You can try lerp 0.1 or lower to slow down the deceleration time.

    lerp(self.speed, normalSpd, 0.1)

    Just don't go too low like 0.0001. Fastest is 1 which is basically instant.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Just change the 3rd number in your deceleration lerp to a lower number, but make sure you use a "dt" calculation rather than a fixed number to keep it frame-rate independent.

    So instead of lerp(X,Y,1) use lerp(X,Y,dt) or lerp(X,Y,dt*2) or dt/2 or 3 etc.

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