Why wont this work properly?

0 favourites
  • 5 posts
From the Asset Store
_______ Huge collection of metal fixtures ________
  • I have these two conditions here that im trying to use to make an attack cooldown. but for some reason this just refuses to work properly. when "CanAttack" is true, i left click and it sets "CanAttack" to False. then after a second, it sets it back to true. this much works, but, for some strange reason, as soon as it sets "CanAttack" back to true, theres roughly a whole second where i can spam left click and it never sets "CanAttack" back to false, allowing the player to spam attack and i just have no clue why it wont work at all. any help?

  • Hi. It's working exactly as you programmed it to, the only issue is that it's not meeting your expectations. But enough philosophizing.

    You can implement firing rate timing in different ways, I usually prefer to make it dynamically dependent on the variable, so that you can realize the improvement of firing rate in the game.

    In your case it is enough just to reset the timer every second.

  • Hi. It's working exactly as you programmed it to, the only issue is that it's not meeting your expectations. But enough philosophizing.

    You can implement firing rate timing in different ways, I usually prefer to make it dynamically dependent on the variable, so that you can realize the improvement of firing rate in the game.

    In your case it is enough just to reset the timer every second.

    Thanks for your reply! unfortunately, the solution you posted does not work. as it just resets the cooldown every second, if you time your attack correctly, you can attack and it will instantly remove the cooldown allowing you to attack twice incredibly quickly. this makes the attack cooldown incredibly inconsistent. id like for it to take exactly 1 second from the frame that the player left clicks on, for the attack cooldown to reset.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I use designs like this.

  • I think in the first snippet, the problem is a misunderstanding on how those events work.

    The mouse event is a trigger, so it is only executed when the left mouse button is clicked. So far so good...

    The following event is not a trigger, so it is executed every tick. That means that as soon as CanAttack is set to false the first time, the actions for CanAttack = false start executing every tick.

    So every tick you have this timer being setup to wait for 1 second and after that setting CanAttack to true.

    The problem with all of that is that by the time CanAttack is set to true the first time, a whole bunch of other Waits for 1 second actions have also been set up, and after each of those finishes, CanAttack will be set to true, making it seem the clicks are not setting CanAttack to false.

    If I understand correctly, to get the behaviour you want, you need to place all the actions in the Mouse trigger. That way CanAttack is set to false, then you wait for 1 second and after the wait is done you set CanAttack back to true. Because everything is in the trigger it will only happen when the mouse is clicked.

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